How to use get_template_directory_uri() to load an image that is in a sub-folder of my theme?

You should echo it and also you are closing your php tag improperly. View source the o/p generated to get some idea img<src=<?php echo get_template_directory_uri().”/assets/img/flexslider/flex-1.jpg”?> alt=”alternative_name”> or you can use bloginfo which is easier to remember and use (You need not echo) <img src=”<?php bloginfo(‘template_url’); ?>/assets/img/flexslider/flex-1.jpg”/>

Editing the custom background CSS

Yes, that is possible. Take a look at the codex and you will see that you can pass arguments with add_theme_support( ‘custom-background’). One of them is the callback function that generates the <style> tags: _custom_background_cb. You can pass your own function as an argument to add_theme_support. Here is the code of the original function (retrieved … Read more

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 to remove hardcoded characters from playlists?

Inside the shortcode function for playlists, there is this line: do_action( ‘wp_playlist_scripts’, $atts[‘type’], $atts[‘style’] ); Hooked into that is wp_playlist_scripts() which hooks the templates into the footer: add_action( ‘wp_footer’, ‘wp_underscore_playlist_templates’, 0 ); add_action( ‘admin_footer’, ‘wp_underscore_playlist_templates’, 0 ); So if you want to replace the templates, you can hook into wp_playlist_scripts after those hooks have been … 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

wp_nav_menu not appearing for a couple pages

I had the same problem, but with a newer version of WordPress (3.7.1). On pages with custom taxonomies of custom posts, the wp_nav_menu was not shown. The solution below worked for me. in functions.php of the theme: add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ ); function my_pre_get_posts($query) { if ($query->get(‘post_type’) === ‘nav_menu_item’) { $query->set(‘tax_query’,”); } }