如何替换 wordpress the_title 中的文本?

How to replace text in wordpress the_title?

我想替换 wp 标题中的文本,
实际上,有一个流行帖子的小部件。
我想替换这个小部件输出中的文本,所以我查看了小部件函数并找到了这段代码:

foreach($popular as $post) :
        setup_postdata($post);
        ?>
    <li>
        <a href="<?php the_permalink(); ?>">
            <?php if ( $show_thumb3 == 1 ) : ?>
                <?php the_post_thumbnail('widgetthumb',array('title' => '')); ?>
            <?php endif; ?>
            <?php the_title(); ?>   
        </a>
blah blah blah...

我已尝试将此行 <?php the_title(); ?> 更改为:

<?php
    $wptitle = the_title();
    $wptitle = str_replace('textbefore', 'textafter', $wptitle);
    echo $wptitle;
?>

但它在实时站点中没有任何作用,也没有任何影响!
如何替换小部件输出中标题中的文本?
如果有两个字符串要替换怎么可能呢?
我应该使用这样的东西吗?:

    <?php
    $wptitle = the_title();
    $wptitle = str_replace('textbefore', 'textafter', $wptitle) && str_replace('text2before', 'text2after', $wptitle);
    echo $wptitle;
?>

试试这个

$wptitle = get_the_title( get_the_ID() );
$wptitle = str_replace('textbefore', 'textafter', $wptitle);
echo $wptitle;
<?php
$wptitle = the_title();
$wptitle = str_replace('textbefore', 'textafter', $wptitle);
echo $wptitle;
?>

替换为

<?php
$wptitle = get_the_title($post->id);
$wptitle = str_replace('textbefore', 'textafter', $wptitle);
echo $wptitle;
?>