Support » Theme: Twenty Seventeen » wp_enqueue_style was called incorrectly

  • Hello,

    This has to do with enqueuing the twentyseventeen-child theme.
    I turned on Debug to check something and got an unexpected PHP Notice that I don’t know what to do to fix it. Unexpected because everything has been working OK. I’m just now seeing this because I turned Debug on for something else.

    PHP Notice: wp_enqueue_style 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 /home/botani05/public_html/botanical-art/wp-includes/functions.php on line 4147

    It says to see Debugging in WordPress for more information but that only tells you how to turn Debug on and off that I’ve already done, which is why I’m seeing the PHP Notice. It gives no information about enqueuing scripts or styles.

    This is what I have in my child theme’s functions.php file in order to get jump-to links in the navigation menu for the front page. This is from https://kinsta.com/blog/twenty-seventeen-theme/#scrolling

    /**
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Force WordPress to Load the Child Theme’s global.js File for a scrollable one-page website (menu item jump)
      If the current page is the front page, WordPress enqueues the child theme’s global.js file. If it does not exist,
       WordPress loads the parent’s global.js. Found at https://kinsta.com/blog/twenty-seventeen-theme/#scrolling //
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    */
    function childtheme_enqueue_styles() { 
       wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
       wp_enqueue_style( 'child-style', 
       get_stylesheet_directory_uri() . '/style.css',
       array( 'parent-style' ),
       wp_get_theme()->get('Version')
       );
    
       if( is_front_page() ){
          wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true );
      }
    }
    add_action( 'wp_enqueue_scripts', 'childtheme_enqueue_styles' );

    What needs to be enqueued differently?

Viewing 1 replies (of 1 total)
  • Moderator Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Can you try taking the ‘wp_enqueue_script’ or ‘wp_enqueue_style’ lines out until you find the one that is responsible?

Viewing 1 replies (of 1 total)
  • The topic ‘wp_enqueue_style was called incorrectly’ is closed to new replies.