custom post types - How to set the seo title tag on a page by page basis?

admin2025-06-05  11

I am storing the SEO title with advanced-custom-fields. How do i set the seo title tag within my single-mypost.php template. This is the place where i can call get_field('title_tag');

I tried adding this to functions.php :

add_filter('wpseo_title', 'filter_product_wpseo_title');
function filter_product_wpseo_title($title) {
    if(  is_singular( 'my_post_type') ) {   
        $title = get_field("title_tag");
    }
    return $title;
}

I am storing the SEO title with advanced-custom-fields. How do i set the seo title tag within my single-mypost.php template. This is the place where i can call get_field('title_tag');

I tried adding this to functions.php :

add_filter('wpseo_title', 'filter_product_wpseo_title');
function filter_product_wpseo_title($title) {
    if(  is_singular( 'my_post_type') ) {   
        $title = get_field("title_tag");
    }
    return $title;
}
Share Improve this question edited Dec 22, 2018 at 20:56 Tintinabulator Zea asked Dec 22, 2018 at 5:43 Tintinabulator ZeaTintinabulator Zea 1298 bronze badges 2
  • 2 And why don’t you just use one of SEO plugins? – Krzysiek Dróżdż Commented Dec 22, 2018 at 6:37
  • 1 And...? You can still set it programmatically using Yoast SEO for example... – Krzysiek Dróżdż Commented Dec 22, 2018 at 19:01
Add a comment  | 

1 Answer 1

Reset to default -1

I added this to functions.php while having Yoast SEO activated, and then it worked!

add_filter('wpseo_title', 'filter_product_wpseo_title');
function filter_product_wpseo_title($title) {
    if(  is_singular( 'my_post_type') ) {   
        $title = get_field("title_tag");
    }
    return $title;
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749075065a316139.html

最新回复(0)