我对 WordPress 还很陌生,所以我不确定这会如何工作。
基本上我有 Yoast 插件来处理 SEO 相关的事情。造成问题的主要问题是描述元标记。
该网站是双语的,我希望描述元标记也能被翻译。 Yoast 目前不提供该选项,除非我得到另一个我不想使用的插件。
就目前情况而言,我被告知可以使用
functions.php
通过 add_action
插入描述元标记。不幸的是,这不起作用,因为它只添加了另一个描述元标记。
目前我的代码如下所示:
function insert_meta_tag_in_head () {
echo '<meta name="description" content="My New content" />';
}
add_action('wp_head', 'insert_meta_tag_in_head', 1);
所以基本上这只是给了我第二个描述元标记。我还在其他线程中看到,如果我想替换标签,我应该使用
do_action
函数。我这样称呼它:
do_action('wp_head', 'insert_meta_tag_in_head');
但这没有任何作用。 我究竟做错了什么?如何更改通过 Yoast 给我的描述标签的内容?
我们之前更改了 Yoast 标题,但是,描述也是我们一直在努力的事情。
总结上面的链接:
您需要过滤
操作才能显示您的 新的描述。wpseo_metadesc
add_filter('wpseo_metadesc', 'new_desc_function');
add_filter('wpseo_title', 'filter_wpseo_title');
add_filter('wpseo_metadesc', 'filter_wpseo_metadesc');
add_filter('wpseo_opengraph_title', 'filter_wpseo_opengraph_title');
add_filter('wpseo_twitter_title', 'filter_product_wpseo_twitter_title');
add_filter('wpseo_opengraph_url', 'filter_product_wpseo_opengraph_url');
add_filter('wpseo_opengraph_desc', 'filter_product_wpseo_opengraph_desc');
add_filter('wpseo_twitter_image', 'filter_product_wpseo_tweeter_image');
这些都是可以用来替换Yoast SEO Premium插件opengraphs的过滤器
wpseo_title , wpseo_metadesc, wpseo_opengraph_title, wpseo_twitter_标题, wpseo_opengraph_url, wpseo_opengraph_desc, wpseo_twitter_image