javascript - && 正在破坏 WordPress 中的页面

标签 javascript html wordpress

我将其添加到我的 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/

相关文章:

c# - 使用 C# 将 Javascript 添加到 ASPX 页面

php - 如何在wordpress中制作一个包含图像和内容的弹出按钮

javascript - 在 jquery 中复制/克隆带有选定选项的下拉列表

javascript - 跳转到 Iframe 中不同部分的父页面上的 anchor 链接

php - 想要将表格行数据显示为 html 中的标题

javascript - 替换 anchor 元素中的 href 属性

Javascript 时间复杂度分析

javascript - 在浏览器中捕捉保存 (Ctrl/Cmd+S) 键盘快捷键?

wordpress - 最小化重定向

php - WP_Query 当元值保存为序列化数组时