Welcome to OStack Knowledge Sharing 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...