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
1 Answer
Reset to default -1I 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;
}