php - 使用过滤器 wpseo_title 更改标题标签

标签 php seo title

我试图更改标题标签并添加一个变量(产品品牌),但该变量没有显示。

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/

相关文章:

php - 如果使用 PHP 在 .css 中显示 IE 和 ff 或 chrome,则显示一种 css 样式

php - 为什么 PHP PDO 在使用持久连接时连接到不同的数据库?

php - 执行 INSERT 查询时获取 MySQL 错误 1064

gwt - 索引重定向 onload 的 HTML 页面

ios - navigationItem 的标题字体是什么?

php - 使用动态字段更新 MySQL

.htaccess - StackOverflow 中的 301 重定向。它是如何运作的?

ssl - 缺少用于 SEO 的基本域证书

python - string.title() 认为撇号是一个新词的开头。为什么?

r - 如何通过在ggplot2中设置“theme(legend.title = element_blank())”来删除多余的空间