Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enqueue global.js #30

Closed
jaredatch opened this issue Jul 30, 2013 · 2 comments
Closed

Enqueue global.js #30

jaredatch opened this issue Jul 30, 2013 · 2 comments
Labels

Comments

@jaredatch
Copy link
Collaborator

Not sure about yall, but on almost every site I do I have at least 1 js file that needs to be enqueued, usually globally.

Should we set something for default as a reference.

This is what I had in my old base theme:

/**
 * Global enqueues
 *
 * @since 1.0.0
 */
function ja_global_enqueues() {
    global $wp_styles;

    // javascript
    wp_enqueue_script( 'global', CHILD_URL . '/lib/js/global.js', array( 'jquery' ), CHILD_THEME_VERSION, false );

    // css
    wp_enqueue_style( 'ie', CHILD_URL . '/lib/css/ie.css' );
    $wp_styles->add_data( 'ie', 'conditional', 'lt IE 9'  );
}
add_action( 'wp_enqueue_scripts', 'ja_global_enqueues' );
@billerickson
Copy link
Owner

Looks good to me. I've never seen that global $wp_styles used for conditionals, neat!

I'd use get_stylesheet_directory() instead of CHILD_URL. WP core recommends using functions rather than globals, and are deprecating them in core I think (couldn't find the ticket). I know these are Genesis global variables, but it's good practice to not use them.

It's a good idea to prefix the javascript and stylesheet slug (ea-global rather than global).

I'd leave the Javascript there, also creating a file in /inc/js/global.js. But I'd have the stylesheet part commented out.

@GaryJones
Copy link
Contributor

I've never seen that global $wp_styles used for conditionals, neat!

http://code.garyjones.co.uk/enqueued-style-sheet-extras

I'd like to see the enqueueing of CSS and JS split into two different functions.

jaredatch added a commit that referenced this issue Aug 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants