WordPress: 22 Powerful Tips And Tricks

Here is a list of 22 techniques that are handy, clever, fun or best practices rarely followed.


1. WordPress Has A Ton Of Built-In Scripts Link

Using the great wp_enqueue_script() and wp_enqueue_style(), you can include styles and scripts easily with dependency management. But did you know that WordPress has a lot of scripts already built in? jQuery, many elements of jQuery UI, jQuery Form, SWF Object, Tiny MCE, Jcrop and Thickbox are just some the better known ones. The whole list can be found in the WordPress Codex.


2. Replace Built-In Scripts By Deregistering Them Link

If you live on the bleeding edge, you can use versions of scripts other than the built-in ones. Using a newer jQuery version is common (though not necessarily good) practice, which can be done in the following way.

But do not do this just to brag about using latest stuff. WordPress includes the version of jQuery that it does to ensure maximum compatibility.

Use another version of jQuery only when encountering compatibility issues, such a plugin that specifically requires it.


3. Force Perfect JPG Images Link

This is a classic example of why working on a team is beneficial. My good friend Lars told me that WordPress doesn’t use 100% quality for images served on the website, to conserve space and bandwidth. He also showed me a solution, of course:

WordPress uses a default quality of 90%. This is fine in most cases; I doubt many people can see the difference. But if top-notch image quality is a must on your website (for a portfolio, photography, etc.), modifying the value might be best.


4. FeedBurner Redirection Link

FeedBurner is used on almost every blog that I’ve worked on, and yet I never know how exactly to set it up by heart. Thanks to Elio for writing “10 Tips to Optimize Your WordPress Theme,” which contains this snippet:


5. Using General Taxonomy Functions Link

A number of taxonomy functions can handle your custom taxonomies as well as the built-in tags and categories. The Codex’s reference of functions contains the full list of taxonomy functions. I particularly like using get_term(), get_terms() and wp_get_object_terms(). To make things more modular, I use these functions as much as I can, even for tags and categories.


6. Setting Up Sessions In WordPress Link

Sessions are great for storing information between pages and are widely used on websites. WordPress doesn’t use them at all internally, so the session is never set. Using the following method, you can start a session on all pages before any output.

Note that, while sessions are generally pretty safe, implement IP checking or added nonce protection just to be on the safe side. As long as you’re transmitting non-sensitive data, though, you’ll fine. Check out Mark Jaquith’s great article on nonces for more info.


7. List All Hooked Functions Link

I started writing a function to do this. When I did a quick Google search, it turned out that WP Recipes had exactly what I needed.

Used without an argument, you’ll get a nice list of all hooked functions. This will be a bit long, so you can specify a hook to narrow the list a bit. This is particularly useful when debugging or fiddling around with hook priorities. Knowing what’s hooked into wp_head() in what order is important, and this function is a great asset!


8. Automatically Add Paragraph Tags To Anything Link

WordPress does this automatically to the content and the excerpt, but there’s no reason not to use it elsewhere. The function responsible for turning double line breaks into paragraphs is wpautop().

Sometimes you’ll want to disable this filter by default, which you can do by removing it from the content and excerpt, like so:


9. Send Emails Using WordPress Link

In the article on “Creating Perfect Emails for Your WordPress Website,” a part of which has to do with using the wp_mail() functions. These functions let you use built-in WordPress awesomeness to send emails to users.

You can also send HTML content by using a filter:


It came as a surprise to me about six months ago that you don’t need any plugins to pull off proper paging (i.e. not just “Previous” and “Next” links); you can do it with a native function. The paginate_links() function is a handy little thing that lets you show pagination for any type of content, not just a WordPress loop.


11. Upload Files With Ease Link

WordPress has a bunch of great uploading functions for everything from checking the file type to finding the uploads directory. A more obscure function is wp_upload_bits(), which you can use to upload a file to the uploads directory.


12. Twitter-Like Time Display Link

This was another shock to me a while back, especially since it has been in WordPress since version 1.5! If you’d like to show viewers a relative date in a human-readable format, like “5 minutes ago” or “one month ago,” try the human_timed_diff() function.


13. Log In As Any User Link

If you’re building a complex website with many roles, being able to switch between them quickly and easily would be useful. The wp_set_auth_cookie() lets you log the current user in based on ID.

Take great care when using this function; left unchecked, it could log every user in as user number 4. Even while testing, I target it specifically to my IP, and maybe even to a special URL string just to be sure. That said, with proper safety, it can be used as part of a custom log-in script.


14. Add Custom Profile Fields In The Admin Area Link

I can’t say that WordPress offers much in the way of profile customization in the administration area. Especially nowadays, when you want to show the Twitter and other social accounts of authors, this is a shortcoming. It can be fixed easily, though. Have a look here:


15. Sanitize URLs With Ease Link

When working with URLs, always make sure they are properly formed and don’t contain any invalid or dangerous characters. The esc_url() function lets you do just that.

Be sure to check out all of the other escape functions. You can find a list of them at the bottom of the page that I linked to in the related section.


16. Empower Text Widgets Link

To make text widgets so much better, you can enable the use of shortcodes in them. This is a great tool for theme developers because it makes your product much more flexible for the user.


17. Add Custom Post Types To The RSS Feed Link

Not being able to do this easily from the admin area is a big issue. Many website owners separate their content into custom posts, and they also want all of their items to show up in the feeds. Never fear — a function is here!

While this is great, it forces all of your post types into the feed. If you’d like to add just some of your custom post types to the feed, you can list them separately.


18. Don’t Break WordPress Loops Link

Multiple loops are great but can wreak havoc if not used correctly. To make sure your loop runs smoothly and you can still use all of the functions that rely on globals, store the original query in a temporary variable.


19. Custom Database Queries Link

If you need something more than what the default WordPress functions give you, you can use $wpdb, the WordPress database class to query the database directly.

This class has great features and functions. Take a look at “Interacting With the WordPress Database” for an in-depth tutorial.


21. Customize WordPress Post Revisions Link

The post revisions feature in WordPress is great, but the majority of users don’t use it. Database entries are created for revisions, even if they are not used. While they’re not a huge hit on your server’s performance, if you don’t use revisions, you can disable them by placing the following code in your wp-config.php file.


21. Styling Author Comments Link

If you’d like author comments to jump out, simply use the bypostauthor class in your CSS.


22. Storing Your Whole Page In A Variable Link

In some cases, storing your whole output in a variable can be very helpful. This allows you to make global changes, compress or obfuscate code and more very easily. All we need is PHP output buffering and two hooks.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA