Forums

pre tag shows slashes, code doesn't?! (8 posts)

  1. Daath
    Member
    Posted 4 years ago #

    Hello!

    I was just wondering, when I write code snippets with the pre-tag the contents gets addslashes() or at least " gets escaped - This is not the case with for example the code-tag...
    Any thoughts on how I remove the escapes using the pre-tag?

    Result when using code-tag:

    printf( "hello" );

    Result when using pre-tag:

    printf( \"hello\" );

    I'm using WP 1.5 final!

    Thanks :)

  2. Daath
    Member
    Posted 4 years ago #

    No takers?

  3. gaemon
    Member
    Posted 4 years ago #

    This is due to the last line of wpautop():
    $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . clean_pre('$2') . '</pre>' ", $pee);

    you can fix this by:
    $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslahes(clean_pre('$2')) . '</pre>' ", $pee);

    hope this helps.

  4. Daath
    Member
    Posted 4 years ago #

    It worked like a charm, thanks! Do you know if they are fixing this in coming releases?

  5. mlambie
    Member
    Posted 4 years ago #

    At the risk of being pedantic, the code should read:

    $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' ", $pee);

    The second stripslashes was originally stripslahes. Easy typo to make. This works well for me.

  6. stulegmo
    Member
    Posted 4 years ago #

    Sorry chaps,
    may you tell me which file to apply these changes?

  7. jgrucza
    Member
    Posted 4 years ago #

    If PHP had namespaces that matched the filenames, it wouldn't be such a pain to find out what functions were in which files.

    For the benefit for anyone else that finds this thread, I found the wpautop function in functions-formatting.php.

    And the fix worked.

  8. ChiliJ
    Member
    Posted 3 years ago #

    I just moved to wordpress. This is immediately the problem I encountered. The solution provided by above works for the problem of appearing backslashes. But then another problem comes: backslashes that I specifically written were removed.

    It seems that the wpautop function is used for auto-formatting p tags. Since I'm hand-coding my posts' HTML and know how to close my p's, the best solution for me is to disable wpautop on my posts by disabling the following line in wp-includes/default-filters.php:

    add_filter('the_content', 'wpautop');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.