1

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;
}
2
  • 2
    And why don’t you just use one of SEO plugins? Dec 22, 2018 at 6:37
  • 1
    And...? You can still set it programmatically using Yoast SEO for example... Dec 22, 2018 at 19:01

1 Answer 1

-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;
}
1
  • If you're using the wpseo_title hook, then that means you have WP SEO installed, and that plugin already has a field for setting the title, so why are you using a custom field for it? Dec 23, 2018 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.