Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use a slider called revoslider and use it via shortcode.

When i use the shortcode and do not use visual editor for insert and save, the slider does not work because WordPress adds <p> into javascript like this :

<p>         <script type="text/javascript"></p>
<p>             var tpj=jQuery;</p>
<p>                                 tpj.noConflict();</p>
<p>             var revapi1;</p>
<p>             tpj(document).ready(function() {</p>
<p>             if (tpj.fn.cssOriginal != undefined)
                    tpj.fn.css = tpj.fn.cssOriginal;</p>
<p>             if(tpj('#rev_slider_1_1').revolution == undefined)
                    revslider_showDoubleJqueryError('#rev_slider_1_1');
                else
                   revapi1 = tpj('#rev_slider_1_1').show().revolution(
                    {
                        delay:9000,
                        startwidth:960,
                        startheight:350,
                        hideThumbs:200,</p>
<p>                     thumbWidth:100,
                        thumbHeight:50,
                        thumbAmount:2,</p>
<p>                     navigationType:"bullet",
                        navigationArrows:"solo",
                        navigationStyle:"round",</p>
<p>                     touchenabled:"on",
                        onHoverStop:"on",</p>
<p>                     navigationHAlign:"center",
                        navigationVAlign:"bottom",
                        navigationHOffset:0,
                        navigationVOffset:20,</p>
<p>                     soloArrowLeftHalign:"left",
                        soloArrowLeftValign:"center",
                        soloArrowLeftHOffset:20,
                        soloArrowLeftVOffset:0,</p>
<p>                     soloArrowRightHalign:"right",
                        soloArrowRightValign:"center",
                        soloArrowRightHOffset:20,
                        soloArrowRightVOffset:0,</p>
<p>                     shadow:2,
                        fullWidth:"off",</p>
<p>                     stopLoop:"off",
                        stopAfterLoops:-1,
                        stopAtSlide:-1,</p>
<p>                     shuffle:"off",</p>
<p>                     hideSliderAtLimit:0,
                        hideCaptionAtLimit:0,
                        hideAllCaptionAtLilmit:0,
                        startWithSlide:0    
                    });</p>
<p>             }); //ready</p>
<p>         </script></p>

Because of this, the code does not work and I don´t understand why WordPress adds these <p> for each line - it´s ridicoulus.

I tried add_filter for content but it also does not work.

share|improve this question

1 Answer 1

You have to either

1) take all the whitespace out of the script so WordPress does not add <p> tags and then the JS will work, or

2) disable autop in the post editor for all posts/pages (see http://codex.wordpress.org/Function_Reference/wpautop ) so WP doesn't add paragraph breaks, or

3) do the following, which leaves autop enabled globally, but lets you disable it with and tags in individual posts and pages.

Add the function below to functions.php and use the two tags

<!-- noformat on --> and <!-- noformat off -->

in your page/post editor, i.e.

    text will be rendered *with* autop

    <!-- noformat on -->

    text will be rendered *without* autop

    <!-- noformat off -->

    text will be rendered *with* autop

Content outside of the two format tags will have autop enabled, as noted.

Add to functions.php of the theme:

// <!-- noformat on --> and <!-- noformat off --> functions

function newautop($text)
{
    $newtext = "";
    $pos = 0;

    $tags = array('<!-- noformat on -->', '<!-- noformat off -->');
    $status = 0;

    while (!(($newpos = strpos($text, $tags[$status], $pos)) === FALSE))
    {
        $sub = substr($text, $pos, $newpos-$pos);

        if ($status)
            $newtext .= $sub;
        else
            $newtext .= convert_chars(wptexturize(wpautop($sub)));      //Apply both functions (faster)

        $pos = $newpos+strlen($tags[$status]);

        $status = $status?0:1;
    }

    $sub = substr($text, $pos, strlen($text)-$pos);

    if ($status)
        $newtext .= $sub;
    else
        $newtext .= convert_chars(wptexturize(wpautop($sub)));      //Apply both functions (faster)

    //To remove the tags
    $newtext = str_replace($tags[0], "", $newtext);
    $newtext = str_replace($tags[1], "", $newtext);

    return $newtext;
}

function newtexturize($text)
{
    return $text;   
}

function new_convert_chars($text)
{
    return $text;   
}

remove_filter('the_content', 'wpautop');
add_filter('the_content', 'newautop');

remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'newtexturize');

remove_filter('the_content', 'convert_chars');
add_filter('the_content', 'new_convert_chars');
share|improve this answer
    
Ok i go to try , thank´s for help me , i put the result when i try , Thank´s ! –  Fran May 31 '13 at 3:21
    
No work me , continue insert these tags , i think the problem the div container use other class , i supose howewer can be the problem i don´t know but i put the function you put here and follow the instructions and continue the same problem , regards ! –  Fran May 31 '13 at 3:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.