我使用一个名为revoslider的滑块,并通过短代码使用它。
当我使用短代码时and do not use visual editor for insert 并保存,滑块不工作,因为WordPress添加了<p>
进入javascript,如下所示:
<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>
因此,代码不起作用,我不理解WordPress为什么添加这些
<p>
每一行都是ridicoulus。
我试过了add_filter
但它也不起作用。
SO网友:markratledge
你要么
1) 去掉脚本中的所有空白,这样WordPress就不会添加<p>
标记,然后JS将工作,或者
2) 禁用autop
在所有帖子/页面的帖子编辑器中(请参见http://codex.wordpress.org/Function_Reference/wpautop ) 因此WP不会添加段落分隔符,或者
3) 执行以下操作autop
全局启用,但允许在单个帖子和页面中使用和标记禁用它。
Add the function below to functions.php and use the two tags
<!-- noformat on -->
和
<!-- 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
如上所述,两个格式标记之外的内容将启用自动转换。
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\');