I’m trying to get the SEO title from a custom taxonomy.
Here’s my current code for it:
$my_yoast_wpseo_title = get_term_meta( $term_id, '_wpseo_title', true );
if( $my_yoast_wpseo_title ){
echo $my_yoast_wpseo_title;
} else {
echo 'No title';
}
It doesn’t work.
So I tried different meta keys like _yoast_wpseo_title
and everything I could find in their docs and other snippets.
Nothing works.
So I checked the complete output of get_term_meta
. Like this:
$my_yoast_wpseo_title = get_term_meta( $term_id );
print_r($my_yoast_wpseo_title);
It shows a lot of meta fields. But the Yoast meta isn’t stored there?!
Is their any other place?
The taxonomy has a custom SEO title and shows it in the frontend.
3
Answers
I found another way to do this:
You can used that with
title
anddesc
without the prefixwpseo_
The Yoast SEO Titles for Terms are stored in the
options
table.This will at least give you the idea you’re after.
This is another solution to get the meta title and meta description out of yoast seo in the taxonomy. Paste this code into archive.php or taxonomy.php of your theme.