Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am calling /js/gallery_sugar.js with the following block of code in my plugin. It works fine while viewing the pages logged in as admin, but it doesn't seem to be running when I am just viewing the page without being logged in as admin:

Here is the code in the plugin:

add_action('init','gallery_sugar_js_init');

function gallery_sugar_js_init() {
    wp_enqueue_script( 'gallery_sugar_js', plugins_url( '/js/gallery_sugar.js', __FILE__ ), array( 'jquery' ) );
    wp_register_style( 'prefix-style', plugins_url('/css/gallery_sugar.css', __FILE__) );
    wp_enqueue_style( 'prefix-style' );
}

Source code while not logged in as admin (This does not work - jquery not called first):

<script type='text/javascript' src='http://localhost/projects/lightbox/wp-content/plugins/custom-gallery/js/gallery_sugar.js?ver=3.7'></script>
<script type='text/javascript' src='http://localhost/projects/lightbox/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>
<script type='text/javascript' src='http://localhost/projects/lightbox/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>

Source code while logged in as admin (This works - jquery called first):

<script type='text/javascript' src='http://localhost/projects/lightbox/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>
<script type='text/javascript' src='http://localhost/projects/lightbox/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>
<script type='text/javascript' src='http://localhost/projects/lightbox/wp-content/plugins/custom-gallery/js/gallery_sugar.js?ver=3.7'></script>

I am trying to work out what I am doing wrong in that it doesn't display in both cases.

share|improve this question
    
Hook on to wp_enqueue_scripts instead of init. –  Andrew Bartel Nov 27 '13 at 0:29
    
Tried it and it does nothing I am afraid –  fakeguybrushthreepwood Nov 27 '13 at 0:44
    
Try registering it with a dependency on jquery instead of adding the dependency in the enqueue function. –  Andrew Bartel Nov 27 '13 at 0:55
    
By non-admin do you mean Front end view? –  sri Nov 27 '13 at 10:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.