哇,这个插件真是一场噩梦。
但我有一个解决方案给你。在链接的描述中,可以使用占位符%FULLTITLE%
而不是%TITLE%
. %FULLTITLE%
为标题应用筛选器。
从…起nxs_functions_adv.php
第19行(&A);20:
if (preg_match(\'/%TITLE%/\', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $msg = str_ireplace("%TITLE%", $title, $msg); }
if (preg_match(\'/%FULLTITLE%/\', $msg)) { $title = apply_filters(\'the_title\', nxs_doQTrans($post->post_title, $lng)); $msg = str_ireplace("%FULLTITLE%", $title, $msg); }
是的,这实际上就是插件中代码的格式
这解决了您的第一个问题。
接下来要做的是将打开的图形信息添加到标题中,并对其应用标题过滤器。例如,facebook(源于WPBeginner):
//Adding the Open Graph in the Language Attributes
function f711_add_opengraph_doctype( $output ) {
return $output . \' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"\';
}
add_filter(\'language_attributes\', \'f711_add_opengraph_doctype\');
//Lets add Open Graph Meta Info
function f711_insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
echo \'<meta property="og:title" content="\' . get_the_title() . \'"/>\';
echo \'<meta property="og:type" content="article"/>\';
echo \'<meta property="og:url" content="\' . get_permalink() . \'"/>\';
echo \'<meta property="og:site_name" content="\' . get_bloginfo( \'title\' ) . \'"/>\';
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library
echo \'<meta property="og:image" content="\' . $default_image . \'"/>\';
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'medium\' );
echo \'<meta property="og:image" content="\' . esc_attr( $thumbnail_src[0] ) . \'"/>\';
}
echo "
";
}
add_action( \'wp_head\', \'f711_insert_fb_in_head\', 5 );
IMPORTANT 请确保尚未包含此信息。例如,YOAST SEO就是这样做的,这可能会让facebook感到困惑。他们将此信息用作链接框的标题。
最后,我建议对您的功能进行修改:丢失in_the_loop()
使过滤器适用于任何地方。此外,正如@PieterGoosen指出的,我跳过了不必要的检查function_exists()
.
function append_album_review_to_title( $title ) {
global $post;
$text = \'Album Review: \';
if ( get_post_type( $post->ID ) == \'album_review\' ){
return $text . $title;
} else {
return $title;
}
}
add_filter(\'the_title\', \'append_album_review_to_title\');