问题描述
我想在正在使用Yoast SEO的wordpress中将产品完整描述用作元描述。有%%excerpt%%
关键字以获得简短说明。但我想完整描述。没有完整说明的关键字。所以我决定使用编码来实现。
<?PHP if ( is_product() ){
echo '<Meta name="description" content="'.the_content().'">';
} ?>
我尝试了这个,还有更多,但是没有人在工作。我从https://yoast.com/help/list-available-snippet-variables-yoast-seo/得到了%%excerpt%%
。
解决方法
关键字:在function.php中的 %% fulldes %%
// define the custom replacement callback
function get_fulldes() {
global $post;
return $post->post_content;
}
// define the action for register yoast_variable replacments
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%fulldes%%','get_fulldes','advanced','Full Description' );
}
// Add action
add_action('wpseo_register_extra_replacements','register_custom_yoast_variables');