使用 Ahrefs WordPress 插件时,可能会遇到这样一种情况:运行内容审核后,看到的结果不完整或为空。
这很可能是因为你的 WordPress 网站使用了 2 个不同的 URL:一个是内部/预发布 URL,另一个是对外公开的 URL。 要让插件正常工作,你可能需要应用更高级的设置:
假设预发布网站的 URL 是 blog.ahrefs.com,而公开 URL 是 ahrefs.com/blog/。
为确保插件能在你的 WordPress 网站中识别到正确的页面,请将以下代码块添加到你的 functions.php 文件(https://developer.wordpress.org/themes/basics/theme-functions/#what-is-functions-php)或添加到你当前启用的主题中。
你需要指定公开 URL 的域名(在我们的示例中为 'ahrefs.com')以及站点的公开 URL(在我们的示例中为 'https://ahrefs.com/blog')。 请记得将这两个字段都替换为你自己的域名和公开 URL:
// Ahrefs domain redirect begin.
define('REPLACEMENT_DOMAIN', 'ahrefs.com'); // public domain name.
define('REPLACEMENT_SITE_PATH', 'https://ahrefs.com/blog'); // public URL of site, without trailing slash.
add_filter( 'ahrefs_seo_post_url', function( $domain ) {
return rtrim( str_replace( home_url(), REPLACEMENT_SITE_PATH, $domain ), '/');
});
add_filter( 'ahrefs_seo_domain', function( $domain ) {
return REPLACEMENT_DOMAIN;
});
add_filter( 'ahrefs_seo_search_traffic_url', function( $domain ) {
return rtrim( str_replace( home_url(), REPLACEMENT_SITE_PATH, $domain ), '/');
} );
// Ahrefs domain redirect end.