• Im using RSS to fetch posts from another site.
    The post titles allways shows like this.

    Post – name ( in this post title the “–” is longer )

    I would like to have post names like this.
    Without using a plugin or some heave stuff.
    I need the short “-” not the long “–”

    Post – name ( in this post title the “–” is shorter )

    I have tried this but doesnt help.
    <?php the_title();echo str_replace("–","-","–"); ?>

    • This topic was modified 5 years, 2 months ago by Gustav.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The the_title() function echos the title out and your string replace isn’t accepting any string to replace. You need to combine the two:

    echo str_replace( '–', '-', get_the_title() );

    The above code will replace the long dash with the short dash in the title and echo the results out.

    Thread Starter Gustav

    (@4ever16)

    Doesnt work. Tryied with different words.
    <?php echo str_replace( 'X', 'text', get_the_title() );?>

    Moderator bcworkz

    (@bcworkz)

    Where are you putting this code? Do you have a custom RSS template? If not, you should be filtering “the_title_rss”. Why wouldn’t the original title have the shorter dash to start with? If there are a lot of such titles to change, there are DB search and replace tools you could use to permanently change all such occurrences.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Replace “–” with “-” without plugin.’ is closed to new replies.