The difference between calling wp_enqueue_scripts to load scripts and styles in custom theme

wp_enqueue_scripts Action Hook: WordPress provides various names (or place holders) that can be used to inject callback functions within WordPress core’s execution lifecycle. These are called action and filter hooks. wp_enqueue_scripts is a WordPress action hook. Note: It’s not wp_enqueue_script, it’s plural: wp_enqueue_scripts. With this hook, we add script or style on the correct time … Read more

How do I check if a menu exists?

Assuming that you have custom Nav Menus implemented properly: Registering nav menu Theme Locations: register_nav_menus( array( ‘parent_page’ => “Parent Page”, ‘page_a’ => “Page A”, ‘page_b’ => “Page B”, //etc ) ); Calling wp_nav_menu() correctly: wp_nav_menu( array( ‘theme_location’ => ‘page_a’ ); …then you can use the has_nav_menu() conditional to determine if a Theme Location has a … Read more

enqueue script for specific shortcode

wp_enqueue_script is not going to work in a shortcode, this is because of the loading order. You could use wp_register_script and then you could wp_enqueue_script in you shortcode function like this example: // Front-end function front_end_scripts() { wp_register_script( ‘example-js’, ‘//example.com/shared-web/js/example.js’, array(), null, true ); } add_action( ‘wp_enqueue_scripts’, ‘front_end_scripts’ ); Then you use this in your … Read more

Including CSS and JS on Admin Screen of Custom Theme Options

If you create an admin theme plugin from the Codex steps, you will notice it says not to insert stylesheets as per above – although the above will work. If you place the following inside your admin theme file, it will serve the same purpose, but uses the wp_enqueue_styles approach: function add_admin_theme_styles() { wp_register_style($handle=”mytheme-theme-admin-styles”, $src … Read more

How to control initial wp_head() output?

Here is the current list of actions that is currently hooked by default to wp_head Reposted here to avoid unnecessary opening multiple browser windows add_action( ‘wp_head’, ‘_wp_render_title_tag’, 1 ); add_action( ‘wp_head’, ‘wp_enqueue_scripts’, 1 ); add_action( ‘wp_head’, ‘feed_links’, 2 ); add_action( ‘wp_head’, ‘feed_links_extra’, 3 ); add_action( ‘wp_head’, ‘rsd_link’ ); add_action( ‘wp_head’, ‘wlwmanifest_link’ ); add_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, … Read more