woof_seo_canonical
在活动筛选搜索期间,过滤页面头部区域输出的规范URL链接标签,允许自定义规范URL。
参数
$canonical_url (string) — 当前筛选搜索页面的清除后的基础URL(不含查询参数)
源文件
ext/url_request/classes/seo.php:376
代码示例
add_filter('woof_seo_canonical', function($url) {
// Force HTTPS for canonical
return str_replace('http://', 'https://', $url);
});
使用说明
- 在 wp_head 中输出 <link rel="canonical" href="..." />。
- 当 do_index() 为 true 时,Yoast 的规范链接被禁用,可能会使用带搜索参数的清除后 URL。
- 该 URL 是不含查询字符串的基础路径,通过 get_cleared_url() 获取。