registered['jquery'] ) ) { return; } $scripts->registered['jquery']->deps = array_values( array_diff( (array) $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) ) ); } /** * Remove Dashicons for visitors who are not logged in. */ public static function dashicons_logged_in_only() { if ( ! is_user_logged_in() ) { wp_dequeue_style( 'dashicons' ); } } /** * Ask WordPress to load queued scripts (and what they depend on) with * "defer". WordPress checks every script and keeps it blocking when an * inline script or a blocking script depends on it. */ public static function defer_scripts() { global $wp_version; if ( is_admin() || version_compare( $wp_version, '6.3', '<' ) ) { return; } $scripts = wp_scripts(); $todo = (array) $scripts->queue; $seen = array(); while ( $todo ) { $handle = array_shift( $todo ); if ( isset( $seen[ $handle ] ) || empty( $scripts->registered[ $handle ] ) ) { continue; } $seen[ $handle ] = true; $todo = array_merge( $todo, (array) $scripts->registered[ $handle ]->deps ); if ( in_array( $handle, self::NO_DEFER, true ) || ! $scripts->registered[ $handle ]->src || $scripts->get_data( $handle, 'strategy' ) ) { continue; } $scripts->add_data( $handle, 'strategy', 'defer' ); } } /* ------------------------------------------------------------------ */ /* SEO / accessibility */ /* ------------------------------------------------------------------ */ /** * Readable text from a media title or file name. * * @param int $attachment_id Attachment. * @param string $src Image URL (fallback). * @return string */ private static function alt_for( $attachment_id, $src = '' ) { $text = $attachment_id ? get_the_title( $attachment_id ) : ''; if ( '' === trim( (string) $text ) && $src ) { $file = pathinfo( (string) wp_parse_url( $src, PHP_URL_PATH ), PATHINFO_FILENAME ); $file = preg_replace( '/-\d+x\d+$|-scaled$|-e\d{10,}$/', '', (string) $file ); $text = ucfirst( trim( preg_replace( '/[\-_.]+/', ' ', (string) $file ) ) ); } return trim( wp_strip_all_tags( (string) $text ) ); } /** * Images added with WordPress image functions. * * @param array $attr Attributes. * @param \WP_Post $attachment Attachment. * @return array */ public static function attachment_alt( $attr, $attachment ) { if ( is_array( $attr ) && ! isset( $attr['alt'] ) && is_object( $attachment ) ) { $attr['alt'] = self::alt_for( (int) $attachment->ID, isset( $attr['src'] ) ? $attr['src'] : '' ); } return $attr; } /** * Images inside post content. Only images without any alt attribute are * changed; alt="" (a decorative image) is respected. * * @param string $tag Image tag. * @param string $context Context. * @param int $attachment_id Attachment. * @return string */ public static function content_img_alt( $tag, $context, $attachment_id ) { if ( ! is_string( $tag ) || preg_match( '/\salt\s*=/i', $tag ) ) { return $tag; } $src = preg_match( '/\ssrc\s*=\s*["\']([^"\']+)["\']/i', $tag, $m ) ? $m[1] : ''; $alt = self::alt_for( (int) $attachment_id, $src ); return '' === $alt ? $tag : preg_replace( '/^ 'Yoast SEO', 'RANK_MATH_VERSION' => 'Rank Math', 'AIOSEO_VERSION' => 'All in One SEO', 'SEOPRESS_VERSION' => 'SEOPress', 'THE_SEO_FRAMEWORK_VERSION' => 'The SEO Framework', 'SQUIRRLY_VERSION' => 'Squirrly SEO', ); foreach ( $known as $constant => $name ) { if ( defined( $constant ) ) { return $name; } } return ''; } /** * Print a meta description from the excerpt, term description or tagline. */ public static function meta_description() { if ( '' !== self::seo_plugin() ) { return; } $text = ''; if ( is_singular() ) { $post = get_queried_object(); if ( $post instanceof \WP_Post && ! post_password_required( $post ) ) { $text = has_excerpt( $post ) ? $post->post_excerpt : strip_shortcodes( $post->post_content ); } } elseif ( is_front_page() || is_home() ) { $text = get_bloginfo( 'description', 'display' ); } elseif ( is_category() || is_tag() || is_tax() ) { $text = term_description(); } elseif ( is_author() ) { $text = get_the_author_meta( 'description', (int) get_query_var( 'author' ) ); } $text = trim( preg_replace( '/\s+/', ' ', wp_strip_all_tags( excerpt_remove_blocks( (string) $text ) ) ) ); if ( '' === $text ) { return; } if ( function_exists( 'mb_strlen' ) && mb_strlen( $text ) > 155 ) { $text = rtrim( mb_substr( $text, 0, 152 ), " ,.;:-" ) . '…'; } echo '' . "\n"; } }