在一些帖子标题中,我有“年”(例如:“Lorem ipsum-2018”),这不是问题。但在博客的另一部分中,我将这些标题称为PHP:
$shortitle = wp_html_excerpt( get_the_title(), 23, \'...\' );
<div class="col-md-9">\' . $shortitle . \'</div>
.
如何删除标题中的年份显示?谢谢:)
更新时间:
找到了str\\u replace函数,但对我来说很奇怪:
$title_long = get_the_title();
$excludeyears = array(" - 2017", " - 2018", " - 2019", " - 2020");
$title_long_exclude_years = str_replace($excludeyears, "", $title_long);
$shortitle = wp_html_excerpt( $title_long_exclude_years, 23, \'...\' );
它显示:Lorem ipsum–201。。。
更新2:
好吧,这是“-”字符的问题,但我没有解决办法。