Support » Fixing WordPress » Replace – with – in post title

  • Resolved Asome

    (@asome)


    Hi!

    How to replace a short dash (-) with a long dash (–) in the post title?

    I found only this (changed inside posts):

    add_filter( 'the_content', 'wpm_tire' );
    function wpm_tire( $content ) {
    	$content = str_replace( "--", "—", $content );
    	$content = str_replace( " - ", " – ", $content );
    	return $content;
    }
    
Viewing 12 replies - 1 through 12 (of 12 total)
  • If it’s the post title you’d want to use the ‘the_title’ filter instead.

    I don’t understand how the code should look like?

    It’s easy.

    Change this line:

    add_filter( 'the_content', 'wpm_tire' );

    to this:

    add_filter( 'the_title', 'wpm_tire' );

    Thanks! But how to combine both?

    Do you know anything abut coding? If so, then it;s simple. If not, that’s OK, but I prefer to ask just in case.

    No unfortunately I do not understand coding. I know HTML quite a bit.

    What I said is all that you need. Follow that and you will be fine.

    If you cant’ follow that, then Id suggest that you try and pay someone else to do it for you.

    Yes, your advice helped, but I need both settings. How to make them work together?

    add_filter( 'the_content', 'wpm_tire' );
    function wpm_tire( $content ) {
    	$content = str_replace( "--", "—", $content );
    	$content = str_replace( " - ", " – ", $content );
    	return $content;
    }
    add_filter( 'the_title', 'wpm_tire' );
    function wpm_tire( $content ) {
    	$content = str_replace( "--", "—", $content );
    	$content = str_replace( " - ", " – ", $content );
    	return $content;
    }

    You need to read up on PHP more. You are close but… not quite there.

    Just remember that a function can’t be declared more than once. And seeing as how you have two functions doing the same thing with the same name… you only should have one.

    I understand that you need to change something in the code, but I don’t know what.

    The code in the very first message I gave as an example.

    I can’t understand how I can replace a short dash with a long dash in the titles and posts.

    Hi, you need to use 2 different function names instead of using the same one. So your code should look something like the following

    add_filter( 'the_title', 'wpm_tire_title' );
    function wpm_tire_title( $content ) {
    	$content = str_replace( "--", "—", $content );
    	$content = str_replace( " - ", " – ", $content );
    	return $content;
    }
    add_filter( 'the_content', 'wpm_tire_content' );
    function wpm_tire_content( $content ) {
    	$content = str_replace( "--", "—", $content );
    	$content = str_replace( " - ", " – ", $content );
    	return $content;
    }

    Ohhhh yes! it is alive, alive! (с) scene from intro Weird Science (tv series).

    THANK you so much! You have helped me many times already =)

    It’s a pity that sometimes you can’t ask directly through private messages.

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.