Joy*_*des 4 php wordpress wordpress-plugin
只是不知道是否有创建的方式自定义变量,这样我可以添加在页面的元标题创建我的自定义变量.
Yoast SEO有预定义变量的列表在这里.
如果我可以创建自己的变量,那将是很棒的.有没有办法得到这个?
提前致谢!
Mos*_*ush 11
你有两种选择.
如果要更改存在的变量,可以这样做:
// define the wpseo_replacements callback
function filter_wpseo_replacements( $replacements ) {
if( isset( $replacements['%%page%%'] ) ){
$replacements['%%page%%'] = 'Page x of y';
}
return $replacements;
};
// Add filter
add_filter( 'wpseo_replacements', 'filter_wpseo_replacements', 10, 1 );
Run Code Online (Sandbox Code Playgroud)
如果你想添加自定义变量,你可以这样做:
// define the custom replacement callback
function get_myname() {
return 'My name is Moses';
}
// define the action for register yoast_variable replacments
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%myname%%', 'get_myname', 'advanced', 'some help text' );
}
// Add action
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');
Run Code Online (Sandbox Code Playgroud)
我希望我对你有所帮助.
有办法,但据我所知,你必须在 Yoast Seo 中获得高级帐户。Yoast SEO 和 Yoast SEO Premium 最重要的功能之一是可以将标题模板和元描述模板添加到主页、所有(自定义)帖子类型、所有(自定义)分类法和其他页面。
\n\n注意:模板变量也可以用于单个帖子、页面和分类法。
\n\n设置/更改您的模板
\n\n您可以通过转到 WordPress 安装的管理员并单击 SEO \xe2\x86\x92 标题和元来更改标题和元模板。
\n\n有关此内容的更多信息并查看该过程的许多图像,请访问此页面:http://kb.yoast.com/article/146-yoast-wordpress-seo-titles-metas-template-variables
\n