我设法找到了以下帖子:https://wordpress.stackexchange.com/a/75168/45611
它基本上满足了我的需要。
/*
* This whole block here changes the og:url that Wordpress Seo Yoast provides
* It uses the addthis_share_url custom field, and if it is not present, it defaults
* to the permalink, just like the plugin does.
*/
add_action(\'get_header\', \'blog_template_add_ob_start\');
add_action(\'wp_head\', \'blog_template_add_ob_end_flush\', 100);
function blog_template_add_ob_start() {
ob_start(\'blog_template_add_filter_wp_head_output\');
}
function blog_template_add_ob_end_flush() {
ob_end_flush();
}
function blog_template_add_filter_wp_head_output($output) {
$altUrl = get_post_custom_values(\'addthis_share_url\')[0];
$url = get_permalink();
if ($altUrl && is_single()) {
$output = str_ireplace(\'<meta property="og:url" content="\' . $url . \'" />\', \'<meta property="og:url" content="\' . esc_attr(esc_url($altUrl)) . \'" />\', $output);
}
return $output;
}
谢谢大家,你很有帮助!