How to use wp_enqueue_script, style when required

You can create a shortcode: function load_scripts() { wp_enqueue_script(‘moder’); wp_enqueue_style(‘styles’); } add_shortcode(‘load_scripts’, ‘load_scripts’); Then use the shortcode to enqueue the scripts/styles: [load_scripts] Or so: do_shortcode(‘[load_scripts]’); In terms of running when required, you have to make sure that if you’re loading something that requires these, that you either execute the shortcode or enqueue those scripts/styles, since … Read more

Display Something in the Header After All Styles are Loaded

Hook to wp_enqueue_scripts with a high priority number. For example: function load_my_style_wpse_90225() { wp_register_style( ‘mystyle’, get_template_directory_uri() .’/path/to/stylesheet.css’); wp_enqueue_style( ‘mystyle’ ); } add_action(‘wp_enqueue_scripts’,’load_my_style_wpse_90225′,1000); That should reasonably load last in line. Basically the same answer as here: Wooslider custom css Refernce http://codex.wordpress.org/Function_Reference/add_action

Checking for ‘gallery’ shortcode using strpos always returns false

You will need global $post to get the $post variable into the scope of that function. function doraemon_scripts() { if( is_single() ) { global $post; if (strpos($post->post_content,'[gallery’) === false){ } else { // wp_enqueue_style( … ); // wp_enqueue_script( … ); } } } add_action( ‘wp_enqueue_scripts’, ‘doraemon_scripts’ ); Using the $post global outside of the Loop … Read more

How to include a file only on dashboard widgets page?

You can use the following code. Asuming that the css file style.css is inside the css folder of your theme: function wpse_126614_enque( $hook ) { if ( ‘widgets.php’ != $hook ) { return; } $template_url = get_template_directory_uri(); wp_enqueue_style( ‘admin-style-widget’, $template_url . ‘/css/style.css’ ); } add_action( ‘admin_enqueue_scripts’, ‘wpse_126614_enque’ );