您使用的代码应该可以工作。
顺便说一句,由于代码不起作用,最好的方法是取消设置og:url
从Jetpack上独立完成?我将获取您的代码并添加我的代码,并在必要时进行编辑:
<?php
/**
* Change HTTPS to HTTP
* @param string $url Default URL.
* @return string Modified URL.
* -----------------------------------
*/
function https_to_http_url( $url ) {
$url = str_replace(\'https://\', \'http://\', $url );
return $url;
}
/**
* Altering Jetpack OG URL
* We\'re going to strip out the og:url produced by Jetpack.
* @param array $tags Array of Open graph tags.
* @return array Modified array of Open graph tags.
* -----------------------------------
*/
function jetpack_removing_og_url( $tags ) {
//unset completely, we\'ll produce our own
unset( $tags[\'og:url\'] );
return $tags;
}
add_filter( \'jetpack_open_graph_tags\', \'jetpack_removing_og_url\' );
/**
* Add custom og:url
* Adding our custom Open Graph URL meta tag on our own.
* -----------------------------------
*/
function wpse233574_custom_og_url() {
//Jetpack-way to retrieve the URL
if ( is_home() || is_front_page() ) {
$front_page_id = get_option( \'page_for_posts\' );
if ( \'page\' == get_option( \'show_on_front\' ) && $front_page_id && is_home() )
$url = get_permalink( $front_page_id );
else
$url = home_url( \'/\' );
} else if ( is_author() ) {
$author = get_queried_object();
if ( ! empty( $author->user_url ) ) {
$url = $author->user_url;
} else {
$url = get_author_posts_url( $author->ID );
}
} else if ( is_singular() ) {
global $post;
$url = get_permalink( $post->ID );
}
//Modifying the URL for our custom purpose
$modified_url = https_to_http_url( $url );
//Finally print the meta tag
echo \'<meta property="og:url" content="\'. esc_url($modified_url) .\'" />\';
}
add_action( \'wp_head\', \'wpse233574_custom_og_url\' );