您需要一组正确的条件:
在循环内部,帖子的ID与URL中的ID相匹配(有点复杂)
。。。其他可选条件将其放入插件或主题中:add_filter( \'the_title\', \'change_my_title\');
function change_my_title ($title) {
if ( in_the_loop() && get_the_ID() === url_to_postid(full_url($_SERVER))) {
$title = $title . " added by plugin";
}
return $title;
}
// Function found here: http://stackoverflow.com/a/8891890/358906
function full_url($s) {
$ssl = (!empty($s[\'HTTPS\']) && $s[\'HTTPS\'] == \'on\') ? true:false;
$sp = strtolower($s[\'SERVER_PROTOCOL\']);
$protocol = substr($sp, 0, strpos($sp, \'/\')) . (($ssl) ? \'s\' : \'\');
$port = $s[\'SERVER_PORT\'];
$port = ((!$ssl && $port==\'80\') || ($ssl && $port==\'443\')) ? \'\' : \':\'.$port;
$host = isset($s[\'HTTP_X_FORWARDED_HOST\']) ? $s[\'HTTP_X_FORWARDED_HOST\'] : isset($s[\'HTTP_HOST\']) ? $s[\'HTTP_HOST\'] : $s[\'SERVER_NAME\'];
return $protocol . \'://\' . $host . $port . $s[\'REQUEST_URI\'];
}