WordPress.org

Ready to get started?Download WordPress

Forums

How to stop WP from inserting `<br />` in my javascript? (11 posts)

  1. Franzilla
    Member
    Posted 9 years ago #

    I'm trying to put a simple javascript timezone map onto one of my pages in WP. I know next to nothing about javascript. I'm moving an html page into WP and had this working just fine with the html version of the page.

    Viewing the source code on my page I found that WP was inserting <br /> tags into the javascript. Can anyone point me in the right direction?

  2. Nick Momrik
    Member
    Posted 9 years ago #

    Why not make a custom page template with the javascript in there?

  3. Franzilla
    Member
    Posted 9 years ago #

    Thanks bunches, did the trick! Seems so obvious now *slaps forehead* but I'm still pretty new at this so thanks :)

  4. Nick Momrik
    Member
    Posted 9 years ago #

    Glad to hear it worked. Trust me...we all need that slap every now and then. After you look at the code for so long it starts to blend in.

  5. rgkeir
    Member
    Posted 9 years ago #

    Doesn't anyone know how to actually stop WP from inserting
    the
    codes in a post. I'm having the same problem but I want to be able to have the javascript in the body of the post rather than being limited to having it in the template only.

    It's driving me nuts and there must be way

  6. rgkeir
    Member
    Posted 9 years ago #

    Duh. How to stop WP from inserting <br /> ( forgot the backticks) is what I meant. Am I going to have to hack the code? No way to block it or turn it off or ......???

  7. lbessant

    Posted 9 years ago #

    Put the JavaScript in an external .js file. Call it from your page or post. For instance:

    <script src="yourscript.js" type="text/javascript"></script>

  8. rgkeir
    Member
    Posted 9 years ago #

    I was thinking of that as a last desperate (or interim) solution, but I really didn't want to have do that - I may do it anyway but not to get around the break problem. But I just found an answer that works for 1.5:

    in functions-formatting.php on (or around) line 56

    function wpautop($pee, $br = 0) - the default was $br = 1
    - which inserts the breaks automatically. I changed it to
    0 and now my javascript works fine - no more auto breaks.

    Further down in the code - line 72 - it says: " if ($br) .....
    optionally make line breaks"
    but there doesn't seem to be an option to disable except by
    editing the code itself.

    What a relief.

  9. Tahongawaka
    Member
    Posted 9 years ago #

    I had been getting frustrated at the <br /> inserted into my posts where a carriage return had been, and had just come to the same conclusion.

    Now, on to hack the code some more to turn it into what it's not designed for...

  10. weschilders
    Member
    Posted 9 years ago #

    This is slightly related question (see my post here).

    I actually want the carriage returns converted to
    but it doesn't seem to apply to custom fields.

    Anyone know how I can activate this (insert a few lines of code to the source?)

    Thanks.

    Wes

  11. weschilders
    Member
    Posted 9 years ago #

    I found the answer I was looking for and thought it should be noted here for future reference, Turns out that the wpautop or nl2br functions needed to be added to the getcustom plugin I was using to call custom fields. See the plugin creator's comment post here.

    Wes

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.