javascript - jquery not loading on wordpressweb page - Stack Overflow

I have Wordpress blog page which imported JS file. JS code should be started after page load, but it�

I have Wordpress blog page which imported JS file. JS code should be started after page load, but it's not working. I don't know why.

Following file exists on server: http://.. /wp-content/themes/XXXX/js/script.js No errors in FF console,

Generated html looks like this:

<html xmlns="" pl-pl>

<head profile="">
    <title>XXXX test &rsaquo; Just another WordPress site</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--
        <meta property="og:title" content="XXXX" />
        <meta property="og:site_name" content="The easiest and fastest way to claim your PAYE tax refund."/>    
      -->

    <link href="http://localhost/wp-content/themes/XXXX/css/bootstrap.min.css" type="text/css" media="screen" rel="stylesheet" />
    <link href="http://localhost/wp-content/themes/XXXXX/style.css" title="very`plaintxt" rel="stylesheet" media="screen,projection" />

    <link rel="stylesheet" type="text/css" media="print" href="http://localhost/wp-content/themes/XXXXX/print.css" />

    <link rel="alternate" type="application/rss+xml" href="http://localhost/?feed=rss2" title="XXXXX test RSS feed" />
    <link rel="alternate" type="application/rss+xml" href=".rss" title="XXXXXX test ments RSS feed" />

    <link rel="pingback" href="http://localhost/xmlrpc.php" />
    <script>
        var theChampSiteUrl = 'http://localhost';
    </script>
    <div id="fb-root"></div>
    <script>
        var theChampFBKey = '';
        var theChampFBLang = 'en_US';
    </script>
    <script>
        var theChampForceFBComment = false;
        var theChampFBCommentTitle = '';
        var theChampFBCommentUrl = 'http://localhost/?p=44';
        var theChampFBCommentColor = '';
        var theChampFBCommentNumPosts = '';
        var theChampFBCommentWidth = '100%';
        var theChampFBCommentOrderby = '';
        var theChampFBCommentMobile = '';
        var theChampFBAppID = '';
        var theChampSiteUrl = 'http://localhost';
        var theChampWPCommentingContent = '';
        var theChampFBCommentingContent = '';
        var theChampCommentingLoadFbFirst = 1;
        var theChampCommentingSwitchWpText = 'Switch to default menting';
        var theChampCommentingSwitchFbText = 'Switch to Facebook menting';
        var theChampCommentingHandle = false;
    </script>
    <script>
        var theChampSharingAjaxUrl = 'http://localhost/wp-admin/admin-ajax.php';
        var theChampCloseIconPath = 'http://localhost/wp-content/plugins/super-socializer/images/close.png';
        var theChampPluginIconPath = 'http://localhost/wp-content/plugins/super-socializer/images/logo.png';
        var theChampHorizontalSharingCountEnable = 1;
        var theChampVerticalSharingCountEnable = 0;
    </script>
    <link rel='stylesheet' id='open-sans-css' href='//fonts.googleapis/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&#038;subset=latin%2Clatin-ext&#038;ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='dashicons-css' href='http://localhost/wp-includes/css/dashicons.min.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='admin-bar-css' href='http://localhost/wp-includes/css/admin-bar.min.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='core-css' href='http://localhost/wp-content/plugins/simple-subscribe/assets/styleFrontEnd.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='the-champ-frontend-css-css' href='http://localhost/wp-content/plugins/super-socializer/css/front.css?ver=3.4.2' type='text/css' media='all' />
    <link rel='stylesheet' id='really_simple_share_style-css' href='http://localhost/wp-content/plugins/really-simple-facebook-twitter-share-buttons/style.css?ver=4.0.1' type='text/css' media='all' />
    <script type='text/javascript' src='http://localhost/wp-includes/js/jquery/jquery.js?ver=1.11.1'></script>
    <script type='text/javascript' src='http://localhost/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>

    <script type='text/javascript' src='http://localhost/wp-content/themes/XXXXX/js/script.js?ver=4.0.1'></script>

    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/social_login/general.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/facebook/sdk.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/facebook/menting.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/sharing/sharing.js?ver=3.4.2'></script>
    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost/xmlrpc.php?rsd" />
    <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://localhost/wp-includes/wlwmanifest.xml" />
    <meta name="generator" content="WordPress 4.0.1" />

    <script type="text/javascript">
        <!--
        var a2a_config = a2a_config || {},
            wpa2a = {
                done: false,
                html_done: false,
                script_ready: false,
                script_load: function() {
                    var a = document.createElement('script'),
                        s = document.getElementsByTagName('script')[0];
                    a.type = 'text/javascript';
                    a.async = true;
                    a.src = '.js';
                    s.parentNode.insertBefore(a, s);
                    wpa2a.script_load = function() {};
                },
                script_onready: function() {
                    if (a2a.type == 'page') {
                        wpa2a.script_ready = true;
                        if (wpa2a.html_done) wpa2a.init();
                    }
                },
                init: function() {
                    for (var i = 0, el, target, targets = wpa2a.targets, length = targets.length; i < length; i++) {
                        el = document.getElementById('wpa2a_' + (i + 1));
                        target = targets[i];
                        a2a_config.linkname = target.title;
                        a2a_config.linkurl = target.url;
                        if (el) {
                            a2a.init('page', {
                                target: el
                            });
                            el.id = '';
                        }
                        wpa2a.done = true;
                    }
                    wpa2a.targets = [];
                }
            };
        a2a_config.tracking_callback = ['ready', wpa2a.script_onready];
        a2a_config.onclick = 1;
        a2a_config.show_title = 1;
        //-->
    </script>
    <script type="text/javascript">
        //<![CDATA[

        ! function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (!d.getElementById(id)) {
                js = d.createElement(s);
                js.id = id;
                js.src = ".js";
                fjs.parentNode.insertBefore(js, fjs);
            }
        }(document, "script", "twitter-wjs");

        //]]>
    </script>
    <style type="text/css" media="all">
        /*<![CDATA[*/
        /* CSS inserted by theme options */

        body {
            font-family: 'times new roman', times, serif;
            font-size: 90%;
        }
        body div#container {
            float: left;
            margin: 0 -200px 2em 0;
        }
        body div#content {
            margin: 3em 200px 0 0;
        }
        body div.sidebar {
            float: right;
        }
        body div#content div.hentry {
            text-align: left;
        }
        body div#content h2,
        div#content h3,
        div#content h4,
        div#content h5,
        div#content h6 {
            font-family: arial, helvetica, sans-serif;
        }
        body div#wrapper {
            max-width: 55em;
            min-width: 35em;
            width: 80%;
        }
        body div.sidebar {
            text-align: center;
        }
        /*]]>*/
    </style>
    <style type="text/css">
        .recentments a {
            display: inline !important;
            padding: 0 !important;
            margin: 0 !important;
        }
    </style>
    <style type="text/css" media="print">
        #wpadminbar {
            display: none;
        }
    </style>
    <style type="text/css" media="screen">
        html {
            margin-top: 32px !important;
        }
        * html body {
            margin-top: 32px !important;
        }
        @media screen and ( max-width: 782px) {
            html {
                margin-top: 46px !important;
            }
            * html body {
                margin-top: 46px !important;
            }
        }
    </style>
</head>

JS file:

$(function () {
    alert("aaa");
    /*
    $('#elp_txt_email').addClass('form-control');
    $('#elp_txt_button').addClass('hide');    
    */
});

I have Wordpress blog page which imported JS file. JS code should be started after page load, but it's not working. I don't know why.

Following file exists on server: http://.. /wp-content/themes/XXXX/js/script.js No errors in FF console,

Generated html looks like this:

<html xmlns="http://www.w3/1999/xhtml" pl-pl>

<head profile="http://gmpg/xfn/11">
    <title>XXXX test &rsaquo; Just another WordPress site</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--
        <meta property="og:title" content="XXXX" />
        <meta property="og:site_name" content="The easiest and fastest way to claim your PAYE tax refund."/>    
      -->

    <link href="http://localhost/wp-content/themes/XXXX/css/bootstrap.min.css" type="text/css" media="screen" rel="stylesheet" />
    <link href="http://localhost/wp-content/themes/XXXXX/style.css" title="very`plaintxt" rel="stylesheet" media="screen,projection" />

    <link rel="stylesheet" type="text/css" media="print" href="http://localhost/wp-content/themes/XXXXX/print.css" />

    <link rel="alternate" type="application/rss+xml" href="http://localhost/?feed=rss2" title="XXXXX test RSS feed" />
    <link rel="alternate" type="application/rss+xml" href="https://XXXXX.disqus./latest.rss" title="XXXXXX test ments RSS feed" />

    <link rel="pingback" href="http://localhost/xmlrpc.php" />
    <script>
        var theChampSiteUrl = 'http://localhost';
    </script>
    <div id="fb-root"></div>
    <script>
        var theChampFBKey = '';
        var theChampFBLang = 'en_US';
    </script>
    <script>
        var theChampForceFBComment = false;
        var theChampFBCommentTitle = '';
        var theChampFBCommentUrl = 'http://localhost/?p=44';
        var theChampFBCommentColor = '';
        var theChampFBCommentNumPosts = '';
        var theChampFBCommentWidth = '100%';
        var theChampFBCommentOrderby = '';
        var theChampFBCommentMobile = '';
        var theChampFBAppID = '';
        var theChampSiteUrl = 'http://localhost';
        var theChampWPCommentingContent = '';
        var theChampFBCommentingContent = '';
        var theChampCommentingLoadFbFirst = 1;
        var theChampCommentingSwitchWpText = 'Switch to default menting';
        var theChampCommentingSwitchFbText = 'Switch to Facebook menting';
        var theChampCommentingHandle = false;
    </script>
    <script>
        var theChampSharingAjaxUrl = 'http://localhost/wp-admin/admin-ajax.php';
        var theChampCloseIconPath = 'http://localhost/wp-content/plugins/super-socializer/images/close.png';
        var theChampPluginIconPath = 'http://localhost/wp-content/plugins/super-socializer/images/logo.png';
        var theChampHorizontalSharingCountEnable = 1;
        var theChampVerticalSharingCountEnable = 0;
    </script>
    <link rel='stylesheet' id='open-sans-css' href='//fonts.googleapis./css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&#038;subset=latin%2Clatin-ext&#038;ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='dashicons-css' href='http://localhost/wp-includes/css/dashicons.min.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='admin-bar-css' href='http://localhost/wp-includes/css/admin-bar.min.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='core-css' href='http://localhost/wp-content/plugins/simple-subscribe/assets/styleFrontEnd.css?ver=4.0.1' type='text/css' media='all' />
    <link rel='stylesheet' id='the-champ-frontend-css-css' href='http://localhost/wp-content/plugins/super-socializer/css/front.css?ver=3.4.2' type='text/css' media='all' />
    <link rel='stylesheet' id='really_simple_share_style-css' href='http://localhost/wp-content/plugins/really-simple-facebook-twitter-share-buttons/style.css?ver=4.0.1' type='text/css' media='all' />
    <script type='text/javascript' src='http://localhost/wp-includes/js/jquery/jquery.js?ver=1.11.1'></script>
    <script type='text/javascript' src='http://localhost/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>

    <script type='text/javascript' src='http://localhost/wp-content/themes/XXXXX/js/script.js?ver=4.0.1'></script>

    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/social_login/general.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/facebook/sdk.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/facebook/menting.js?ver=3.4.2'></script>
    <script type='text/javascript' src='http://localhost/wp-content/plugins/super-socializer/js/front/sharing/sharing.js?ver=3.4.2'></script>
    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost/xmlrpc.php?rsd" />
    <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://localhost/wp-includes/wlwmanifest.xml" />
    <meta name="generator" content="WordPress 4.0.1" />

    <script type="text/javascript">
        <!--
        var a2a_config = a2a_config || {},
            wpa2a = {
                done: false,
                html_done: false,
                script_ready: false,
                script_load: function() {
                    var a = document.createElement('script'),
                        s = document.getElementsByTagName('script')[0];
                    a.type = 'text/javascript';
                    a.async = true;
                    a.src = 'http://static.addtoany./menu/page.js';
                    s.parentNode.insertBefore(a, s);
                    wpa2a.script_load = function() {};
                },
                script_onready: function() {
                    if (a2a.type == 'page') {
                        wpa2a.script_ready = true;
                        if (wpa2a.html_done) wpa2a.init();
                    }
                },
                init: function() {
                    for (var i = 0, el, target, targets = wpa2a.targets, length = targets.length; i < length; i++) {
                        el = document.getElementById('wpa2a_' + (i + 1));
                        target = targets[i];
                        a2a_config.linkname = target.title;
                        a2a_config.linkurl = target.url;
                        if (el) {
                            a2a.init('page', {
                                target: el
                            });
                            el.id = '';
                        }
                        wpa2a.done = true;
                    }
                    wpa2a.targets = [];
                }
            };
        a2a_config.tracking_callback = ['ready', wpa2a.script_onready];
        a2a_config.onclick = 1;
        a2a_config.show_title = 1;
        //-->
    </script>
    <script type="text/javascript">
        //<![CDATA[

        ! function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (!d.getElementById(id)) {
                js = d.createElement(s);
                js.id = id;
                js.src = "https://platform.twitter./widgets.js";
                fjs.parentNode.insertBefore(js, fjs);
            }
        }(document, "script", "twitter-wjs");

        //]]>
    </script>
    <style type="text/css" media="all">
        /*<![CDATA[*/
        /* CSS inserted by theme options */

        body {
            font-family: 'times new roman', times, serif;
            font-size: 90%;
        }
        body div#container {
            float: left;
            margin: 0 -200px 2em 0;
        }
        body div#content {
            margin: 3em 200px 0 0;
        }
        body div.sidebar {
            float: right;
        }
        body div#content div.hentry {
            text-align: left;
        }
        body div#content h2,
        div#content h3,
        div#content h4,
        div#content h5,
        div#content h6 {
            font-family: arial, helvetica, sans-serif;
        }
        body div#wrapper {
            max-width: 55em;
            min-width: 35em;
            width: 80%;
        }
        body div.sidebar {
            text-align: center;
        }
        /*]]>*/
    </style>
    <style type="text/css">
        .recentments a {
            display: inline !important;
            padding: 0 !important;
            margin: 0 !important;
        }
    </style>
    <style type="text/css" media="print">
        #wpadminbar {
            display: none;
        }
    </style>
    <style type="text/css" media="screen">
        html {
            margin-top: 32px !important;
        }
        * html body {
            margin-top: 32px !important;
        }
        @media screen and ( max-width: 782px) {
            html {
                margin-top: 46px !important;
            }
            * html body {
                margin-top: 46px !important;
            }
        }
    </style>
</head>

JS file:

$(function () {
    alert("aaa");
    /*
    $('#elp_txt_email').addClass('form-control');
    $('#elp_txt_button').addClass('hide');    
    */
});
Share Improve this question edited Aug 17, 2015 at 7:38 P.K. asked Dec 23, 2014 at 11:13 P.K.P.K. 1,7726 gold badges28 silver badges63 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 8

Try this:

You can wrap your javascript inside a self-invoking function, then pass jQuery as an argument to it, using $ as the local variable name. For example:

(function($) {
   $(document).ready(function(){
      alert('aaa');
   });
}(jQuery));

The jQuery library included with WordPress is set to the noConflict() mode. This is to prevent patibility problems with other JavaScript libraries that WordPress can link.

In the noConflict() mode, the global $ shortcut for jQuery is not available.

Actually this should work:

jQuery(document).ready(function(){
   alert('aaa');
});

Not sure if its related to this issue but I have encountered this issue frequently so documenting it anyway in this context is a good idea...

In my case the issue was that Ajax form handler not being called after form submit. Instead it would directly branch to the 'action' parameter given in the form.

The basic issue was due to repeated switching of WYSIWYG and HTML editors in the wordpress, somehow the ajax form submit handler was mented out by automatically by inserting ![CDATA[.

The solution is to disable WYSIWYG while editing wordpress posts and delete the ![CDATA[ keyword before the scripts...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744074324a4554113.html

相关推荐

  • javascript - jquery not loading on wordpressweb page - Stack Overflow

    I have Wordpress blog page which imported JS file. JS code should be started after page load, but it�

    9天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信