我可以没有在网站标题/标题上呈现的句号吗?


Can I not have full-stops rendered on a websites heading/titles

我的一个Wordpress网站的内容管理是由一个人不会停止在标题/标题的末尾使用句号。我厌倦了手动跟踪线索。

是否有一种方法可以让脚本阻止它们被渲染。类似于不渲染双空格的方式?

正如其他人提到的,你可以钩到wordpress页面标题,但你不能在内容中的其他标题标签这样做。你能做的就是写一点javascript。这里我使用jquery,它包含在wordpress:

$('h1,h2,h3,h4,h5').each(function(){
    var title = $(this).text();
    if(title.slice(-1)=='.'){
        $(this).text(title.slice(0, -1));
    }
});

是的,给你的functions.php添加一个过滤器。

add_filter( 'the_title', 'removeFullstop');
function removeFullStop($title) {
    if (substr($title, -1) == '.') {
        $title = rtrim($title, ".");
    }
    return $title;
}

如果你想允许多个点在结尾,你需要通过AND substr($title, -2) != '.'扩展if子句。

更新:上面的代码实际上在点显示之前删除了它,但它将被保存到数据库中。所以最好使用下面的代码:

add_filter( 'wp_insert_post_data' , 'removeFullstop' , '99', 2 );
function removeFullstop( $data , $postarr ) {
    if (substr($title, -1) == '.') {
        $data['post_title'] = rtrim($data['post_title'], ".");
    }
    return $data;
}
http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data

试试这个

echo str_replace(".","",$title);