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
    And why don’t you just use one of SEO plugins? – Krzysiek Dróżdż Dec 22 '18 at 6:37
  • 1
    And...? You can still set it programmatically using Yoast SEO for example... – Krzysiek Dróżdż Dec 22 '18 at 19:01
-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;
}
| improve this answer | |
  • 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? – Jacob Peattie Dec 23 '18 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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