Support » Fixing WordPress » How to stop WP from inserting `<br />` in my javascript?

  • 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?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Why not make a custom page template with the javascript in there?

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

    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.

    Doesn’t anyone know how to actually stop WP from inserting
    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

    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 ……???

    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>

    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.

    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…

    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?)



    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.


Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to stop WP from inserting `<br />` in my javascript?’ is closed to new replies.