隐藏标题中的文本(WordPress)



我正在使用Wordpress,并希望隐藏标题为"受保护:Pavanjot&Amandeep's Wedding"的"受保护"一词,我希望标题的其余部分保持原样。

我猜使用自定义 css 我可以针对以下代码来隐藏单词?不过,我不确定如何实现这一目标。

<header class="entry-header page-header">
        <h1 class="entry-title">Protected: Pavanjot &amp; Amandeep’s Wedding</h1>
    </header>

我想隐藏这个词,或者删除它,这样剩下的文本就会左对齐,不会留下空白。

任何帮助都很棒,谢谢。

我不认为你可以在不修改标记的情况下用 CSS 做到这一点(然后你可以删除文本(,但你可以用几行 JS 来做到这一点。

<h1 class="entry-title">Protected: Pavanjot &amp; Amandeep’s Wedding</h1>
<script>
var entryTitle = document.querySelector('.entry-title'),
  text = entryTitle.innerHTML;
entryTitle.innerHTML = text.substring(text.indexOf(" "), text.length);
</script>

如果这是你的帖子标题,那么把这个函数放在你的函数中.php,你的问题就会得到解决。

function change_title($title) {
    if (strpos($title, 'Protected:') !== false) {
        $title = str_replace("Protected:","",$title);
    }
    return $title;
}
add_filter('the_title', 'change_title');

希望这对你有用。

最新更新