Eight Hidden Gems in the WordPress Function Reference

WordPress is like a big ocean to me. It has a big set of great APIs, it has some awesome functionality and you can make almost any kind of websites you can imagine.

But in this grand ocean as a content management system, there are some tiny bits of code that are being overlooked. In this tutorial, we're going to have a quick look at eight interesting WordPress functions.

This one is –hopefully– going to be an interesting tutorial for most of you. I need to admit that I was blown away with some of the functions, saying "There is a function for that?"

Some of them might not be as interesting as others, but I'm pretty sure that you will enjoy reading this article and learning about these hidden gems!

Cloaking Email Addresses in Your Content

Have you ever needed to share an email address in your WordPress blog or website? You most likely have, and if you ever cared about not getting caught by spam robots which crawl the web for email addresses, telephone numbers and things like that, you've searched for a solution to hide the email addresses from those tiny evil robots.

I know I have, and little did I know, there was already a core WordPress function for it: antispambot().

Usage

Looks like a fun little function, but the problem is that WordPress Core is set to force this function to run in your post title, post content and comments. Justin Tadlock posted about this about 4 years ago, mentioning that the function breaks the URLs. Luckily, the issue was fixed in version 3.0.1, but I see that it still breaks things.

For example, if you misspell WordPress in a code example and the little "p" is important for the code, it breaks the code.

Fortunately, the solution to the problem is also simple. Head to your theme's functions.php file (or create a new plugin for this issue) and paste the code below:

My personal opinion: Yes, I think that capitalization of the word "WordPress" is extremely important and I'm irritated every time I see people writing "Wordpress", but WordPress shouldn't force people to display the word correctly.

Stripping Shortcodes!

There might be some cases that you need the shortcodes of the text to be omitted: You may use part of the content for a "Next Post" preview, you may have switched to a new theme and don't want to display texts of shortcodes that are not run anymore, and so on.

Refreshing the Rewrite Rules

If you're a plugin developer (or a theme developer who has to invade the plugin territory for some reason) and you need to add a rewrite rule for a function of yours, you have to tell your users to refresh the rewrite rules by visiting the Permalinks options page and clicking the "Save Changes" button without any change, or you can make your code to flush the rewrite rules itself, with the flush_rewrite_rules() function!

Usage

Keeping up with the example above, let's say you wrote a plugin that introduces a new custom post type. Upon activation and deactivation, you need to refresh the rewrite rules for your custom post type's permalinks to work:

The Codex expresses that flushing the rewrite rules is an expensive function, in terms of server resources usage. That's why we should only do it on the activation and deactivation of your plugin or theme.

This one is probably the most well-known function among these hidden gems, but I realized that many WordPress developers seem to forget about this useful little function.

If you're dealing with any kind of rewrite rules (like if you're creating a new post type or taxonomy), you should keep this function in mind.

Detecting Mobile Visitors of Your Website

Like strip_shortcodes(), wp_is_mobile() is also easy to explain: It allows you to detect users that are using mobile devices to connect to your website.

Usage

A perfect Adaptive Web Design tool, if you ask me. Plus, you can remove some elements that are irrelevant for mobile users, or add some like a banner for your mobile application.

Enqueueing Inline CSS

Ever needed to include a variable, inline style for your plugin or theme? Of course you did! Enqueueing external CSS files with WordPress' wp_enqueue_style() function (and its companions) is pretty slick but it lacks the funcionality to include inline CSS styles.

Usage

Probably the easiest one to use among the functions in this article, along with wp_is_mobile().

Wrapping Everything Up

As you can see from what we went over in the article, there are some pretty useful functions in the WordPress Core and the Functions Reference at the Codex. You may have heard about some of them but I bet you didn't know all about them, right?

Do you know any core WordPress functions like these ones up there? Share your knowledge with us by commenting below!

And if you liked the article, don't forget to share it with your friends!