Any advantage of using wp_scripts and is_IE when enqueuing scripts

To extend on @gmazzap suggestion on not using globals when you can use wp_scripts(), there is a shortcut for wp_scripts() for adding conditional comments called wp_script_add_data and likewise wp_style_add_data for conditional styles. So the correct way to use conditionals as of WordPress 4.2 is like this: /** * IE enqueue HTML5shiv with conditionals * @link … Read more

What does l10n.js do in WordPress 3.1? And how do I remove it?

It contains the convertEntities() function that (as the name says) converts HTML entities to their actual value. It is mostly used for scripts that send over localization data from PHP to the JS side using wp_localize_script(). Just search for l10n_print_after in the code base and you see it a lot. The data you add in … Read more

How can i get the name parameter defined in get_header?

There is an action get_header that you can use. In your theme’s functions.php, register a callback for that action: add_action( ‘get_header’, function( $name ) { add_filter( ‘current_header’, function() use ( $name ) { // always return the same type, unlike WP return (string) $name; }); }); You could also write a little helper class that … Read more

force enqueue script to be first in order of prominence

You just need to enqueue your scripts before plugin does it. You can do it by setting priority to 0 for your hook. For example, do the following: add_filter( ‘wp_enqueue_scripts’, ‘wpse8170_enqueue_my_scripts’, 0 ); // or if you enqueue your scripts on init action // add_action( ‘init’, ‘wpse8170_enqueue_my_scripts’, 0 ); function wpse8170_enqueue_my_scripts() { wp_enqueue_script( ‘myscript’, ‘http://path/to/my/script.js’, … Read more

How to add stylesheets only to pages with specific shortcode?

2 questions so 2 answers 🙂 Why is the current functions.php not working and adding styles to all pages? I’m not sure if it’s the global call or the if statement… It doesn’t work because of the order in which these functions are called. Your shortcode callback is called during rendering post content (most probably … Read more

How can I remove the site URL from enqueued scripts and styles?

Similar to Wyck’s answer, but using str_replace instead of regex. script_loader_src and style_loader_src are the hooks you want. <?php add_filter( ‘script_loader_src’, ‘wpse47206_src’ ); add_filter( ‘style_loader_src’, ‘wpse47206_src’ ); function wpse47206_src( $url ) { if( is_admin() ) return $url; return str_replace( site_url(), ”, $url ); } You could also start the script/style URLs with a double slash … Read more

WordPress Code Flow

Probably the Program Flow on ToolPress is something for you: WordPress 3.0 Program Flow File Inclusions (Default Request); PDF. Contains important filenames, constants and hooks. My Favorite Cheat Sheet so far for the code flow stuff.

Add tags to the section via functions.php

The hook you’re looking for is specifically wp_head which could look something like this: function theme_xyz_header_metadata() { // Post object if needed // global $post; // Page conditional if needed // if( is_page() ){} ?> <meta name=”abc” content=”xyz” /> <?php } add_action( ‘wp_head’, ‘theme_xyz_header_metadata’ ); I believe in the long run though, since WordPress is … Read more