我将其添加到我的 WordPress page
if (script.readyState && script.onload!==null){
script.onreadystatechange= function () {
if (this.readyState == 'complete') mce_preload_check();
}
}
并且 &&
被转换为
if (script.readyState && script.onload!==null){
我将它粘贴到 WordPress HTML View 中,我确保它没问题,但 WordPress 一直显示它。如何解决?
最佳答案
您需要禁用 WP 的自动格式设置。 WP 即使在 html 编辑器中也会自动格式化,空格和换行符会破坏你的 javascript。
使用这个插件 http://wordpress.org/extend/plugins/wp-no-format/
2015 年 4 月 8 日更新:插件已过时但仍然适用于我。
这也有效:将插件直接添加到 functions.php 并将您的 javascript 括在 <!-- noformat on -->
中和 <!-- noformat off -->
标签
添加到 functions.php 文件:
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');
关于javascript - && 正在破坏 WordPress 中的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6195635/