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。
- URL 是不带查询字符串的基本路径,源自 get_cleared_url()。