$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom post types - How to set the seo title tag on a page by page basis?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin10PV0评论

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;
}
Post a comment

comment list (0)

  1. No comments so far