• This problem followes me since several month, and I don’t know how to solve it. When I try to add some gallery plugin, it wont’t work and wordpress gives me that message:

    Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in C:\xampp\htdocs\bib5\wp-includes\functions.php on line 3996
    and consola (about e.g. galleria plugin):

    and consola (there is with galleria plugin):

    TypeError: jQuery(…).galleria is not a function
    <script type=”text/javascript”>jQuery(document).ready(function(){ jQuery(“#amw_g…
    /

    Becouse I have this problem third time I think, I do something wrong. Maybe I add something incorrectly in function.php. Maybe it’s something with wp_register_script and enqueue. I try find answer, but still I don’t what exactly. Sometimes even if I delate everything from function.php, I still have this php error message. So please, if you can, take a quickly look at my function.php, and say me what I could to do wrong…

    
    <?php
    /*
    function my_admin_bar_init() {
    remove_action('wp_head', '_admin_bar_bump_cb');
    }
    add_action('admin_bar_init', 'my_admin_bar_init');
    
    /*menu*/
    function register_my_menus(){
      register_nav_menus(
        array(
              'main' => __( 'Main Menu' ),
              'quickMenu' => __( 'Quick Menu' ),
              'archiwum' => __('Archiwum'),
              'galeria' => __('galeria')
             )
     );
    }
    add_action('init', 'register_my_menus');
    
    require_once ('inc/wp_bootstrap_navwalker.php');
    
    function addStyleAndScripts_init(){
    
    	wp_register_script('jquery-js',
    	'https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js', false, '3.1.0');
    	wp_enqueue_script('jquery-js'); 
    
    	wp_register_style('core', get_bloginfo('template_directory'). '/css/core.css','core');
    	wp_enqueue_style('core');
    
    	wp_register_style('img', get_bloginfo('template_directory'). '/css/img.css','img');
    	wp_enqueue_style('img');
    
    	wp_register_style('bootstrap-css', get_bloginfo('template_directory'). '/bootstrap/css/bootstrap.min.css');
    	wp_enqueue_style('bootstrap-css');
    
    	wp_register_script('bootstrap-js', get_bloginfo('template_directory'). '/bootstrap/js/bootstrap.min.js');
    	wp_enqueue_script('bootstrap-js', array('jquery-js'),null,false);
    
    	wp_register_script('bootstrap-font', get_bloginfo('template_directory'). '/bootstrap/font/bootstrap-glyphicons.tiff');
    	wp_enqueue_script('bootstrap-font', array('jquery-js'),null,false);
    }    
    add_action('init', 'addStyleAndScripts_init');
    
    ?>
    
    • This topic was modified 8 years, 1 month ago by eFKa13.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi eFKa13,

    Please replace the last line of your provided code in function.php i.e. add_action(‘init’, ‘addStyleAndScripts_init’);
    with one of the following line.

    1. add_action(‘ wp_enqueue_scripts’, ‘addStyleAndScripts_init’);
    2. add_action(‘admin_enqueue_scripts’, ‘addStyleAndScripts_init’);
    3. add_action(‘login_enqueue_scripts’, ‘addStyleAndScripts_init’);

    The first one will solve the issue if you are using these scripts and styles on front-end i.e. on visiting site pages as a end user.
    The second one will be useful if you are enqueuing the scripts and styles for back-end pages. i.e. wp-admin pages from admin Dashboard.
    The third one can be used if you want to include the scripts and styles on core login pages.

    So according to your need add anyone in your function.php file.

    Hope this will work for you.

    Thanks

    Thread Starter eFKa13

    (@efka13)

    Thank you very much, it’s really helpful. Only Galleria plugin still won’t work (it could be some problem with them), but diffrent gallery plugins work wonderfull now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_enqueue_scripts and every galley plugin won’t work’ is closed to new replies.