Support » Fixing WordPress » XHTML script blocks help required

  • I’m in the process of finishing of a plugin which injects some javascript into the content, to be XHTML complient i am using the format –

    <script language=”JavaScript” type=”text/javascript”>
    // <![CDATA[
    // ]]>

    however the template-functions-post.php file line 57 –

    $content = str_replace(‘]]>’, ‘]]>’, $content);

    Which replaces the end comment within each script blocks!

    I have tried adding the filter with a high number for the priority (so its executed last) but i take it the function that invalidates my code is called after the filters are applied.

    Other than commenting out this line, is there anything i can do to stop this happening?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try using external script?

    that wont work as this is a content filter that needs to call a function that has already been included as an external script…

    i.e. this needs to happen several times within the same page with different args. the function itself was externaly loaded in the head portion.

    first, I recommend you get rid of the language attr and use this format.

    <script type="text/javascript">
    /* <![CDATA[ */
    // content of your Javascript goes here
    /* ]]> */

    And second, you can call the script differently in a post, like with an onclick? Perhaps you could post an example of the page so I can grok your voodoo.

    This is not for processing a form submission – these are script blocks i am inserting into the content area of a wordpress page. Using –
    add_filter('the_content', 'myfiltername');

    the function in template-functions-post.php file line 57 –

    $content = str_replace(']]>', ']]>', $content);

    would still alter your sugessted replacement as the terminating part of the CDATA node will be changed.

    The code example I gave was just for valid xhtml (dropping language etc.). I realise it doesn’t solve your problem.

    I don’t understand what you’re trying to do well enough. I would benefit from a full example (and even a link). Perhaps someone else can help with the info you’ve given.

    my problem is caused by these function that are searching for the XHTML comment end markers and remplacing part of it with the HTML entitiy for the greater than symbol.

    the_content is the hook i am using to inject script as above, i need to know how to get WP to stop this behaviour – do i have to edit the core files or is there a more correct method.

    This looks like a bit on an unfortunate oversight in that these functions are inadvertantly replacing what can be a valid structural piece of code in XHTML for what looks like the sake of making a more link look like “]]>”.

    This is the kind of thing i am trying to do in the plugin –

    function embedSomeScript($text) {
    $text = eregi_replace('SOME REGEX PATTERN','<script type="text/javascript">'.chr(10).'// <![CDATA['.chr(10).'SOME JAVASCRIPT;'.chr(10).'// ]]>'.chr(10).'</script>',$text);

    #Add filter

    add_filter('the_content', 'embedSomeScript');

    The guts of the functions i have left out as its not their function and what the plugin does that I am woried about – what i am worried about is specifically the injection of XHTML fiendly Javascript into the content of a WP page or post.

    Any pointers would be apreciated.
    Thanks in advance.

    I think you really need to have the javascript as an external file, and then just insert the call to it through your hook. Is there a reason why that might not work for you?

    N.B. Scrufty = Norbit ( at home, i can never remember my WP password and dont take my work machine home that often… aplogies for the confsion)

    This is what i am doing, i.e. in the head i inject the include to the external javascript file.

    In order to “insert the call” i need to insert inline within the page – i need to insert a script block, hence my problem!

    In any case i am asking for help with a specific problem which is to do with WP treatment of CDATA nodes within the content area, not about the reason for the process. There is anoteher way i could do what i need (i think) by triggering a crawl over the document model in the footer – but this is much more involded and should not be nescacary.

    If anyone can advise on my specific problem as detailed in my previous posts (i.e. the CDATA – “]]>” getting changed to “]]>”) how to stop it or process the content area after the offending script in wp_includes has been run then your help ould be greatly apreciated. I am trying to avoid editing the include as i want to stick to the plugin approach.

    Thanks in advance

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘XHTML script blocks help required’ is closed to new replies.