我试图更改标题标签并添加一个变量(产品品牌),但该变量没有显示。
add_filter('wpseo_title', 'filter_product_wpseo_title');
function filter_product_wpseo_title() {
return 'hello'. $_GET[$mysite_slugs['product-brand']] .'hello';
};
}
也试过这个但是没有成功
add_filter('wpseo_title', 'filter_product_wpseo_title');
function filter_product_wpseo_title() {
$productbrand = $_GET[$mysite_slugs['product-brand']];
return 'hello'. $productbrand .'hello';
};
}
最佳答案
我假设您的 URL 具有参数 .com/?product-brand=foo
。确保您已将优先级添加到过滤器中。这应该可以解决问题!
add_filter('wpseo_title', 'filter_product_wpseo_title', 10, 1);
function filter_product_wpseo_title($title) {
$title = 'hello '. $_GET['product-brand'] .' hello';
return $title;
}
关于php - 使用过滤器 wpseo_title 更改标题标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41012012/