Tagtips

How to Network Deactivate a WordPress Plugin

Duh! Hit “Network Deactivate” in the Network Admin, right? Yeah…. Next time, think twice before you Network Activate a WordPress plugin. It’s not too easy to deactivate it, while keeping it activated on blogs that actually use it. I wrote a little CLI script to activate a plugin of your choice on all blogs in a network: define( 'ABSPATH', '/path/to/wordpress/' ); require(...

Disable Object Cache Addition/Invalidation in WordPress

You can temporarily disable object caching in WordPress‬ by calling: wp_suspend_cache_addition( true ); Ref. You can turn addition back on by passing false as the only argument. There’s a similar approach for object cache invalidation. However, there’s a big chance persistent object caching plugins won’t implement these functions like WordPress built-in object caching does, so...

Clear DNS Cache in Google Chrome

You can navigate to chrome://net-internals/#dns to clear the DNS cache in Google Chrome. This helps when juggling virtual hosts in your /etc/hosts file, as well as the dscacheutil -flushcache command in OS X, to flush system-wide DNS cache.

Plugin Headers for Must-Use Plugins

You don’t necessarily need a plugin header for mu-plugins. Must-use plugins will be loaded regardless. Leaving the header out helps when you need to test something real quick, but when you see that your “test” starts shaping into a real plugin, do add a descriptive header — that’s just good practice :)

Default Post Thumbnails in WordPress

Justin Tadlock wrote about the right ways to add default post thumbnails to your WordPress themes. One method is to filter on post_thumbnail_html, and the second method is to simply use else with has_post_thumbnail. The second method is easier to understand, straightforward and future-proof. The filter in the first method would only work well when we need to change the markup of the thumbnail...

Order By Post Meta DATE in WP_Query

Sorting by post meta in WP_Query is quite easy with the orderby argument set to meta_value. If your meta value is a number, you can use meta_value_num, however, if you run into a situation where you have a date string, like 2012-06-15, both meta_value and meta_value_num won’t give you the desired results. Luckily, you can hook into the posts_orderby filter and do some custom SQL, like this:...

How to Remove the Publish Box from a Post Type

I’ve been working plugin, where a post type was meant to only be read from the admin panel, but never edited. Removing the capabilities to edit the post type is one piece of the puzzle, and actually hiding the publish box is another. Have you ever heard people say WordPress is written using its own APIs? Well this is a perfect example: add_action( 'add_meta_boxes'...

Quick tip: Hide the Home Item on Your Front Page in WordPress

The title says it all — this one-liner CSS will hide the home item from your navigation menu, when you’re on the home page: body.home .current-menu-item { display: none; } If you’re not yet using wp_nav_menu to build your navigation menus, then, uhm, wake up! Also, the snippet relies on the body_class usage in your theme, and if your theme doesn’t use one, uhm, wake up! :)...

Never Set Defaults in the Database

Speaking of defaults, NEVER SET DEFAULTS IN THE DATABASE. Not ever. The theme options you store in the DB should always, always, *always* be something the user has selected. If the user selects the default, then that’s fine to set in the DB. but you don’t set it in the DB just because it’s not set at all. get_theme_mod has a second option for the default value. So does get_option for that matter...

Default Custom Background for WordPress 3.4

Custom backgrounds are handled through add_theme_support since WordPress 3.4, and although you can add your custom callback to wp_head, you don’t need you. You can simply pass a default-image to add_theme_support for your custom background: add_theme_support( 'custom-background', array( 'default-image' => get_template_directory_uri() . '/images/default-background.png', ) ); The default...