WordPress.org

Ready to get started?Download WordPress

Forums

.js files only load when I am logged into wordpress admin (6 posts)

  1. cucocreative
    Member
    Posted 2 years ago #

    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: http://www.cucocreative.co.uk/client_folio/the-dungeons/

    I have set up a guest subscriber account so you can see what I mean:
    http://www.cucocreative.co.uk/login
    u/n guest
    p/w guest

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

  3. cucocreative
    Member
    Posted 2 years ago #

    the only thing that may help within this page: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    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="http://www.cucocreative.co.uk/my_scripts/script.js"></script>
    
    <script type="text/javascript">
    $(document).ready(function(){
    
    	$(".btn-slide").mouseenter(function(){
    		$("#sneekyPanel").animate({'height' : "68px"}, "fast");
    	})
    	$(".btn-slide").mouseleave(function(){
    		$("#sneekyPanel").animate({'height' : "34px"}, "slow");
    
    	})
    
    });
    </script>

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

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    that will mean the javascript files are called on every page

    Not if you only load them based on a conditional.

  5. cucocreative
    Member
    Posted 2 years ago #

    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.

  6. cucocreative
    Member
    Posted 2 years ago #

    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_deregister_script('jquery');
            wp_register_script('jquery', 'http://www.cucocreative.co.uk/my_scripts/jquery-1.6.1.min.js', false, '1.6.1');
            wp_enqueue_script('jquery');
            wp_enqueue_script( 'smoothscroll', 'http://www.cucocreative.co.uk/my_scripts/smoothscroll.js', array('jquery') );
            wp_enqueue_script( 'smoothscroll', 'http://www.cucocreative.co.uk/my_scripts/jquery.ImageOverlay.js', 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.

Topic Closed

This topic has been closed to new replies.

About this Topic