diff --git a/2026-04-05_21-16-47.png b/2026-04-05_21-16-47.png new file mode 100644 index 00000000..cd1a3e39 Binary files /dev/null and b/2026-04-05_21-16-47.png differ diff --git a/2026-04-05_21-36-02.png b/2026-04-05_21-36-02.png new file mode 100644 index 00000000..60c8cee7 Binary files /dev/null and b/2026-04-05_21-36-02.png differ diff --git a/2026-04-05_21-37-03.png b/2026-04-05_21-37-03.png new file mode 100644 index 00000000..3639fbb3 Binary files /dev/null and b/2026-04-05_21-37-03.png differ diff --git a/wp-content/themes/twentytwentyfour/functions.php b/wp-content/themes/twentytwentyfour/functions.php index ebd78673..0d2b5087 100644 --- a/wp-content/themes/twentytwentyfour/functions.php +++ b/wp-content/themes/twentytwentyfour/functions.php @@ -146,6 +146,16 @@ endif; add_action( 'init', 'twentytwentyfour_block_styles' ); +/** + * Enable base theme supports used by SEO integrations. + * + * @return void + */ +function twentytwentyfour_theme_setup() { + add_theme_support( 'title-tag' ); +} +add_action( 'after_setup_theme', 'twentytwentyfour_theme_setup' ); + /** * Enqueue block stylesheets. */ @@ -539,6 +549,93 @@ function twentytwentyfour_has_seo_plugin() { return defined( 'WPSEO_VERSION' ) || defined( 'RANK_MATH_VERSION' ); } +/** + * Resolve SEO source page id for custom and WooCommerce contexts. + * + * @return int + */ +function twentytwentyfour_seo_context_page_id() { + if ( is_admin() ) { + return 0; + } + + if ( is_page( array( 'test1', 'faq', 'contacts', 'delivery', 'service' ) ) ) { + return (int) get_queried_object_id(); + } + + if ( function_exists( 'is_cart' ) && is_cart() ) { + return (int) wc_get_page_id( 'cart' ); + } + + if ( function_exists( 'is_checkout' ) && is_checkout() && ! is_order_received_page() ) { + return (int) wc_get_page_id( 'checkout' ); + } + + if ( function_exists( 'is_shop' ) && is_shop() ) { + return (int) wc_get_page_id( 'shop' ); + } + + return 0; +} + +/** + * Use Yoast SEO title from related page for custom templates. + * + * @param string $title Current Yoast title. + * @return string + */ +function twentytwentyfour_yoast_context_title( $title ) { + $page_id = twentytwentyfour_seo_context_page_id(); + + if ( $page_id <= 0 ) { + return $title; + } + + $custom_title = (string) get_post_meta( $page_id, '_yoast_wpseo_title', true ); + + if ( '' === trim( $custom_title ) ) { + return $title; + } + + $post = get_post( $page_id ); + + if ( function_exists( 'wpseo_replace_vars' ) && $post instanceof WP_Post ) { + $custom_title = wpseo_replace_vars( $custom_title, $post ); + } + + return wp_strip_all_tags( $custom_title ); +} +add_filter( 'wpseo_title', 'twentytwentyfour_yoast_context_title', 20 ); + +/** + * Use Yoast SEO description from related page for custom templates. + * + * @param string $description Current Yoast description. + * @return string + */ +function twentytwentyfour_yoast_context_metadesc( $description ) { + $page_id = twentytwentyfour_seo_context_page_id(); + + if ( $page_id <= 0 ) { + return $description; + } + + $custom_description = (string) get_post_meta( $page_id, '_yoast_wpseo_metadesc', true ); + + if ( '' === trim( $custom_description ) ) { + return $description; + } + + $post = get_post( $page_id ); + + if ( function_exists( 'wpseo_replace_vars' ) && $post instanceof WP_Post ) { + $custom_description = wpseo_replace_vars( $custom_description, $post ); + } + + return wp_strip_all_tags( $custom_description ); +} +add_filter( 'wpseo_metadesc', 'twentytwentyfour_yoast_context_metadesc', 20 ); + /** * Get long-form SEO text for cart and checkout pages. * diff --git a/wp-content/themes/twentytwentyfour/template-parts/test1-shared-header.php b/wp-content/themes/twentytwentyfour/template-parts/test1-shared-header.php index d1b1dc98..e89fc008 100644 --- a/wp-content/themes/twentytwentyfour/template-parts/test1-shared-header.php +++ b/wp-content/themes/twentytwentyfour/template-parts/test1-shared-header.php @@ -25,7 +25,7 @@ $test1_header_mode = isset( $test1_header_mode ) ? $test1_header_mode :