WordPress.org

Support

Support » How-To and Troubleshooting » editing wptexturize

editing wptexturize

  • I have edited wptexturize previously, only to find all my changes gone when I updated WordPress.

    I can edit my theme by creating a child theme and not have to worry about losing my changes.

    Is there a way to edit wptexturize – or create a “child” version, or add an override to functions (or some other) file – so that I won’t lose the changes on update?

    Thanks!

Viewing 10 replies - 1 through 10 (of 10 total)
  • You can hook in to the_content and/or other WordPress functions that print out text and make any replacement you want to it directly. Example:

    add_filter( 'the_content' , 'themename_special_replacements' , 12);
    
    function themename_special_replacements( $text ) {
            $content = str_replace( '@' , 'at' , $text );
            return $text;
    }

    Add this to the functions.php file of your child theme. The code above replaces @ with “at” in WordPress content (the main text field of posts and pages).

    That looks good, I will give it a try.
    What is the 12 for?

    This didn’t work. 🙁

    I copied your code directly and nothing changed.

    Other suggestions?

    Hi! There is an error in my code. Instead of returning $text you should return $content. So change return $text; to return $content; and it should work fine.

    Also to reply to your previous question the number 12 specifies in which order the function is supposed to execute relative to other WordPress functions. You want a higher number than 10 if you want it to execute after other functions.

    http://codex.wordpress.org/Function_Reference/add_filter

    Thanks for clarifying.
    In fact, with your explanation I was able to figure out why it still wasn’t working wasn’t working.

    When I pasted your code directly, the @ symbol did indeed change to ‘at’. However, I need to unchange characters that wptexturize changes, and that wasn’t working … until I changed the 12 to a 1.

    But, I can only change one character with this code.
    Is there a way to change multiple characters?

    Specifically:
    wptexturize currently changes ‘…’ to ‘…’
    This is fine when I use an ellipsis, but I occasionally end sentences with four dots – an ellipsis plus a period to signify end of sentence (as you are supposed to do). But wptexturize changes it to the special character … followed by a period, which is larger in the font and looks silly.
    So I want to have this:
    change ‘ … ‘ to ‘ … ‘
    AND
    do not allow wptexturize to change ‘…’ to ‘…’

    I can make the first instance, but the other still exists in wptexturize, so it keeps happening.

    And I can’t keep the three dots. I’ve tried changing ‘…’ to ‘…’ (the same thing) but wptexturize overrides it with the …, even though I can change ‘…’ to anything else just fine.

    I hope I explained that properly! lol
    Thanks 🙂

    Not sure I understand your … problem but you can change as many things as you like by just duplicating the line that does the replacement like so

    function themename_special_replacements( $text ) {
            $content = str_replace( '@' , 'at' , $text );
            $content = str_replace( '%' , 'percent' , $text );
            $content = str_replace( '#' , 'hash' , $text );
            return $content ;
    }

    I don’t understand why it would work when you set the number to 1 instead of 12. 12 should make it run after wp_texturize not before. You want it to run after so that you can override whatever wp_texturize is doing.

    I should have mentioned that I tried simply repeating the $content line and it did not work.
    Just to be sure I wasn’t missing something, I copied your code above directly. It replaced ‘#’ with ‘hash’, but did not change the other two.

    I don’t understand WordPress inner workings enough to explain why, all I know is when I use 12 for characters already defined by wptexturize, it doesn’t work, but it works when I use 1. For characters not defined by wptexturize, the number doesn’t matter, it works either way.

    Yeah I see what you mean. That means that the first two but no the third have already been replaced with something else before the function runs. So the function can not find @ and % because they don’t exist in the content anymore.

    I’m sorry I haven’t been able to help you better. I don’t have time to investigate this more today but if I have later I will get back to you. I’m sure there is a way to do this without having to change core files, it just requires some research.

    I appreciate all your effort and look forward to your response when you have the time. Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘editing wptexturize’ is closed to new replies.
Skip to toolbar