• Philip

    (@philipwalter)


    Okay, I have been digging through the forums for hours now. I have also looked through the codex page on using javascript, but I cannot find an answer to my problem.

    All I want is to be able to add a <script></script> tag to my post without WP filtering it out when it shows up in a browser. Seems like a simple desire, but here are the things I have done so far to no avail:

    1) disabled visual editor in my profile
    2) called the .js file in the header.php
    3) installed Text Control Plugin and played with the various options
    4) physically edited the kses.php file to allow <script> tags and to allow <p> elements to have an “id” attribute

    All this gets me to a point where I am seeing the proper code in the editor, and there is no character formatting on my code lines, but my <script></script> tags are still being stripped on output to a browser. It’s driving me batty. Does anyone have any suggestions?

    Link to site – https://arkansashealthcareers.com – you can see my issue in the top post – if you view source, you will see that the javascript is completely naked, having been stripped of its <script></script> tags.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Philip

    (@philipwalter)

    I appreciate your response, esmi. Unfortunately, the instructions there are completely useless, so long as WP continues to strip out the <script></script> markup.

    I read through the codex page earlier, and it clearly states, “To include a Javascript inside a post, you need to combine both the call to the script file with the call to the Javascript itself,” then gives the following example:

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

    This is exactly what I have done, but it’s useless on output, because if you view source, all <script></script> markup has been removed. I have no trouble using javascript this way elsewhere in my template files, so this is clearly related to the filtering functions of WP. Is anyone aware of a solution to this issue?

    Maybe an alternative would be to use a custom field, then conditionally include the script inside the template (single.php or page.php as appropriate), avoiding the issues you’ve outlined.

    Thread Starter Philip

    (@philipwalter)

    That is a thought, but I would still like to be able to show videos in posts within the loop.

    What exactly do you mean by “use a custom field?” I would add a custom field within a post that would say/do what exactly?

    Did you have a look at wp_enqueue_script?

    Thread Starter Philip

    (@philipwalter)

    I hadn’t seen that before, esmi. It gives me something to chew on. My problem is actually coming from the fact I’m running WPMU, which apparently has more strident filters on javascript than full versions of WordPress itself.

    That said, in the interest of helping some other poor sap who might have the same issues, I used the less filters plugin to retain script tags on single post pages; however, I was using a plugin called advanced excerpt in my loop on my home page, which was still stripping the tags. After much research, I found this thread, indicating the plugin itself was missing one line of code, so that fixed that problem.

    All that said, I will be exploring the wp_enqueue_script function in the interest of having safer javascript includes.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Having a <script> html tag in a post’ is closed to new replies.