• All of my embedded javascript within posts stopped working in 4.2.3. I have it embedded as noted in the codex here.

    The format is:

    <script type="text/javascript" src="/scripts/updatepage.js"></script>
    <script type="text/javascript">
    <!--
    updatepage();
    //--></script>

    If I make an HTML file with this same code and open it in the root of the same web server, the javascript runs fine. So something in 4.2.3 seems to have broken javascript embedded in posts. I believe it was working before 4.2.3.

Viewing 12 replies - 16 through 27 (of 27 total)
  • Thread Starter Hesadanza

    (@hesadanza)

    I’m not sure I understand the question. I haven’t changed the way the JS is embedded. It follows the format:

    <script type="text/javascript" src="/scripts/updatepage.js"></script>
    <script type="text/javascript">
    <!--
    updatepage();
    //--></script>

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I think the method for adding JavaScript into the post in that Codex article is obsolete. Try a workaround for now: https://www.ads-software.com/plugins/javascript-per-page/

    Thread Starter Hesadanza

    (@hesadanza)

    Does that plugin allow you to call javascript from a certain place in the post/page? It looks like it just loads javascript generally for a post/page.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Looks like it does call JavaScript generally. Are you sure you don’t want to go down the jQuery route?

    Thread Starter Hesadanza

    (@hesadanza)

    I used javascript in the method noted because that was the method documented in the codex. If there is a way to do the same thing with jQuery from within a post/page, then yes, I could probably use that, but I wouldn’t know how to convert my function to jQuery, or how to call it from within a post/page.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Looks like it’s going to be fixed, yay!

    Thread Starter Hesadanza

    (@hesadanza)

    Great! Is there any kind of workaround in the meantime? For example, it seems that removing the “<!–” and “//–>” makes it work again. Is it ok to just call the function directly without these tags?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Yea, but I thought WordPress would strip stuff out if you didn’t use those tags? If it doesn’t, then it’s fine.

    Thread Starter Hesadanza

    (@hesadanza)

    Since my script just calls a function and nothing more, it might work ok without the tags. There’s not much that WP could strip.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    It’s an old technique for browsers that didn’t support the <script> tag, so the JS code wouldn’t appear on the page.

    All is OK with WordPress 4.2.4
    Thanks!

Viewing 12 replies - 16 through 27 (of 27 total)
  • The topic ‘Embedded post javascript stopped working in 4.2.3’ is closed to new replies.