Support » Themes and Templates » .js files only load when I am logged into wordpress admin

  • I think this started when I upgraded WP recently – probably with 3.1.2 – upgrading to 3.1.3 didn’t fix it.

    I have three lines of code:

    <script type="text/javascript" src="mypathtofile/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="<mypathtofile/smoothscroll.js"></script>
    <script type="text/javascript" src="mypathtofile/jquery.ImageOverlay.js"></script>

    I’ve added to my header, both before and after the wp_head function and I also tried it in the footer but these three lines are only added to the displayed page if I am logged into the WP admin area and the grey bar is at the top of the page. Otherwise they are missing and the jquery functionality is broken.

    I know the path to the files is correct, as the link to the .js files when I’m logged in and the code is actually shown.

    Help, it’s doing my head in.

    An example page:

    I have set up a guest subscriber account so you can see what I mean:
    u/n guest
    p/w guest

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi


    Forum Moderator

    the only thing that may help within this page:

    is to add a block of code to the functions.php but then that will mean the javascript files are called on every page which I don’t want.

    What I don’t understand is why is problem is with only 3 out of the 5 javascript files I’m including, it load the last two fine:

    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
    		$("#sneekyPanel").animate({'height' : "68px"}, "fast");
    		$("#sneekyPanel").animate({'height' : "34px"}, "slow");

    Also why does it work fine, if I am logged in as an admin?



    Forum Moderator

    that will mean the javascript files are called on every page

    Not if you only load them based on a conditional.

    but why do 2 JavaScript scripts load but 3 more are not included until you log in?

    Plus why has this only just recently become a problem, does WP handle scripts differently now.

    I’ll have to google how to write conditional statements to see if that will work.

    Right, found some time to sort this out.

    I added:

    function my_init() {
        if (!is_admin()) {
            // comment out the next two lines to load the local copy of jQuery
            wp_register_script('jquery', '', false, '1.6.1');
            wp_enqueue_script( 'smoothscroll', '', array('jquery') );
            wp_enqueue_script( 'smoothscroll', '', array('jquery') );

    to my functions file and the scripts are now loading, now I just need to figure out home to make it conditional to only call it on the homepage.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘.js files only load when I am logged into wordpress admin’ is closed to new replies.