I see Yoast stores the snippet variables in the database. I'd like to get their values and ship them via the WP REST API. I'd also like to keep the Admin functionality for Administrators and the default settings for scalability.
I'm shipping the values off to a different application, but I can't ship the placeholders.
They can obviously get parsed because that's how they display in the frontend. I just don't see how to do it.
In the database you can see:
_yoast_wpseo_title %%title%% %%page%% %%sep%% %%sitename%%
On the front end you can see:
<title>About - Cool Site Name</title>
I see Yoast stores the snippet variables in the database. I'd like to get their values and ship them via the WP REST API. I'd also like to keep the Admin functionality for Administrators and the default settings for scalability.
I'm shipping the values off to a different application, but I can't ship the placeholders.
They can obviously get parsed because that's how they display in the frontend. I just don't see how to do it.
In the database you can see:
_yoast_wpseo_title %%title%% %%page%% %%sep%% %%sitename%%
On the front end you can see:
<title>About - Cool Site Name</title>
Share
Improve this question
edited Sep 28, 2018 at 8:18
Pratik Patel
1,1111 gold badge11 silver badges23 bronze badges
asked Sep 28, 2018 at 6:00
Josh SmithJosh Smith
1411 silver badge12 bronze badges
3 Answers
Reset to default 2Ok here is how I parsed the snippets in case anyone else needs to know
$id = get_the_ID();
$post = get_post( $id, ARRAY_A );
$yoast_title = get_post_meta( $id, '_yoast_wpseo_title', true );
$yoast_desc = get_post_meta( $id, '_yoast_wpseo_metadesc', true );
$metatitle_val = wpseo_replace_vars($yoast_title, $post );
$metatitle_val = apply_filters( 'wpseo_title', $metatitle_val );
$metadesc_val = wpseo_replace_vars($yoast_desc, $post );
$metadesc_val = apply_filters( 'wpseo_metadesc', $metadesc_val );
echo $metatitle_val;
echo "<br>";
echo $metadesc_val;
Yoast's SEO plugin has a nice API. You can probably get this with a filter like
add_filter( 'wpseo_options', function ( $arr ) {
return $arr;
} );
Basically this is the answer I was looking for from this question:
function yoastVariableToTitle( $post_id ) {
$yoast_title = get_post_meta( $post_id, '_yoast_wpseo_title', true );
$title = strstr( $yoast_title, '%%', true );
if ( empty( $title ) ) {
$title = get_the_title( $post_id );
}
$wpseo_titles = get_option( 'wpseo_titles' );
$sep_options = WPSEO_Option_Titles::get_instance()->get_separator_options();
if ( isset( $wpseo_titles['separator'] ) && isset( $sep_options[ $wpseo_titles['separator'] ] ) ) {
$sep = $sep_options[ $wpseo_titles['separator'] ];
} else {
$sep = '-'; //setting default separator if Admin didn't set it from backed
}
$site_title = get_bloginfo( 'name' );
$meta_title = $title . ' ' . $sep . ' ' . $site_title;
return $meta_title;
}
https://stackoverflow/questions/41361510/is-there-any-way-to-get-yoast-title-inside-page-using-their-variable-i-e-ti
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742409799a4438581.html
评论列表(0条)