How do I defer or async this WordPress javascript snippet to load lastly for faster page load times?

Or more universal way: function add_async_forscript($url) { if (strpos($url, ‘#asyncload’)===false) return $url; else if (is_admin()) return str_replace(‘#asyncload’, ”, $url); else return str_replace(‘#asyncload’, ”, $url).”‘ async=”async”; } add_filter(“clean_url’, ‘add_async_forscript’, 11, 1); so you can add async to any script without code changes, just add #asyncload to script url as: wp_enqueue_script(‘dcsnt’, ‘/js/jquery.social.media.tabs.1.7.1.min.js#asyncload’ )

wp_nav_menu change sub-menu class name?

There is no option for this, but you can extend the ‘walker’ object that WordPress uses to create the menu HTML. Only one method needs to be overridden: class My_Walker_Nav_Menu extends Walker_Nav_Menu { function start_lvl(&$output, $depth) { $indent = str_repeat(“\t”, $depth); $output .= “\n$indent<ul class=\”my-sub-menu\”>\n”; } } Then you just pass an instance of your … Read more

WordPress get plugin directory

I would suggest to use a WordPress internal constant to solve this case: $my_plugin = WP_PLUGIN_DIR . ‘/my-plugin’; if ( is_dir( $my_plugin ) ) { // plugin directory found! } Alternative The other valid alternative is to compute the path from the URL which is more complex/confusing. I would not use this code: $plugins_url = … Read more

WordPress: Disable “Add New” on Custom Post Type

There is a meta capability create_posts that is documented here and is used by WordPress to check before inserting the various ‘Add New’ buttons and links. In your custom post type declaration, add capabilities (not to be confused with cap) and then set it to false as below. register_post_type( ‘custom_post_type_name’, array( ‘capability_type’ => ‘post’, ‘capabilities’ … Read more

Local wordpress install only shows home page, all other pages Not Found

Log in to the admin panel (localhost/sitedirectory/wp-admin) and go to Settings->Permalinks and click Save Changes. Permalinks often need to be rebuilt after mirroring a site and updating the site url. You don’t need to change any settings, just hit save and it will rebuild the permalinks with the selected options. Also make sure the Apache … Read more

WordPress get user by meta data

Since WP v3.1 it’s ridiculously easy to search for a user by his/her meta key. Use the function get_users($args) (WP Documentation) The function takes an array of parameters, in your case you need get_users(array( ‘meta_key’ => ‘parent_id’, ‘meta_value’ => ’42’ ))