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’,”); } }

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