Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

java - Exclude JS (that itself calls urls) on WP pages

The following code makes several filter functions work on our website, and was written by a former dev. It triggers obnoxious behavior when used with third party js (reloading forms on click, loading errors on calendar functions, etc).

When commented out, it fixes so many problems other problems but breaks our filtering functions. The syntax seems to be a loopy double negative thing.

! function(o) {
    function t() {
        var t = o("#current-page-id").attr("class");
        o("#wp-admin-bar-edit .ab-item").attr("href", window.location.protocol + "//" + window.location.host + "/wp-admin/post.php?post=" + t + "&action=edit"), console.log(window.location.host + "/wp-admin/post.php?post=" + t + "&action=edit")
    }

I've attempted to dump it into its own file, then execute it conditionally (only on pages 12 and 16) in functions.php as follows:

function excludetroublescript() {
    if(is_page(12,16)) {
        wp_enqueue_script('january21-js.js','/assets/js', array('jquery'),'',false);
    }
}
add_action('wp-enqueue-script','excludetroublescript');

I find myself needing to code on occasion, but am clearly no engineer. I've given this quite a bit of time. Is there a quick fix that tidies up the original syntax or allows this to be included only on the pages we need it?

Thanks for any clues!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...