我目前有一个Wordpress网站使用squirly进行SEO。然而,在归档页面上,它使用属于归档页面的第一个内容页面的描述/标题。
例如,在我的住宿档案页面上,列出了所有的酒店,标题是"Hotel 1",描述是"Hotel 1 is a beautiful…"。相反,他们应该引用标题"住宿列表",并描述"这些是所有的酒店……"。我正试图为此编写一个覆盖-我确实在这里列出了一个Yoast SEO - https://wordpress.stackexchange.com/questions/61472/using-php-to-overwrite-or-replace-title-tag-while-using-yoast/61523#61523?newreg=a3496de25de941a7bb16089b1912653b但这不起作用,大概是因为wpseo_title是特定于Yoast的过滤器。
我当前的代码是:
<?php get_header();
if ( is_archive() ) {
add_filter('wpseo_metadesc', 'filter_product_wpseo_metadesc');
function filter_product_wpseo_metadesc($wpseo_metadesc) {
if( is_singular( 'product') ) {
$wpseo_metadesc = "This is a big test of stuff";
}
return $wpseo_metadesc;
}
} ?>
有没有人知道一个过滤器,或类似的,可以覆盖我的归档页面的SEO,无论是特定的squirly SEO,或一个将在一般工作?
亲切的问候詹姆斯。
确保在" wp_head " (get_header();)之前添加钩子
你可以这样写:
if (is_archive()){
add_filter('sq_title', 'filter_product_wpseo_metadesc');
function filter_product_wpseo_metadesc($wpseo_metadesc){
if (is_singular('product')){
$wpseo_metadesc = "This is a big test of stuff";
}
return $wpseo_metadesc;
}
} get_header();
你可以通过调用过滤器:sq_title和sq_description来改变squirly的标题和描述