jeudi 26 mai 2016

How to replace text in wordpress the_title?

I want to replace a text in wp title ,
Actually, There's a widget for popular posts.
I want to replace a text in output of this widget, So I looked around the widget functions and I found this code :

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...

I've tried to change this line <?php the_title(); ?> to :

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

But it did nothing in the live site and nothing affected at all!
How can I replace a text in the title in widget output?
How will it be possible if there are two strings that I want to replace ?
Should I use something like this ?:

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire