Deep within the WordPress core you can find a pool of useful functions which are overlooked for unknown reasons. Let’s take a quick look at 6 WordPress functions and learn how to use them along the way. Hopefully, this post is going to be an interesting tutorial for most of you.

Antispambot

This is probably one of the most well-hidden functions in the WordPress codebase. This function aims to convert an email into HTML entities in order to mask email addresses from evil scrapers.

[php]
$email = ‘mymail@mail.com’;
echo ‘You can contact me at ‘ . antispambot( $email ) . ‘ any time’;
[/php]

Human_time_diff

This function outputs the difference between two timestamps and is presented in a human readable format like “10 mins”, “1 hour”, “3 days”. It has some similarity with the popular Twitter “time ago” function, and is considered to be quite useful for displaying when the post was last modified.

[php]
echo ‘This post was published ‘ . human_time_diff( get_the_time( ‘U’ ), current_time( ‘timestamp’ ) ) . ‘ ago’;
[/php]

Get_post_meta

Despite the fact that this one is quite often used function – how it works is not-so-common knowledge. If <code>get_post_meta()</code> queries the database each time it is used, pulling metadata helps to cache it all and the cached values are used on all subsequent metadata retrievals.

[php]
$all_meta = get_post_meta( 14 );
[/php]

Wpautop

The aim of this function is to wrap the content in paragraphs converting line breaks in strings of text to <br/> tags, and making a double line break into a new paragraph by ending the first paragraph with </p>, and starting a new one with <p>. Besides, it opens and closes the entire string with paragraph tags, so that the whole text is formatted correctly.

[php]
<h2>What Our Clients Say</h2>
<?php echo wpautop( $user_comment ) ?>
[/php]

Wp_is_mobile

This is a little-known built-in function of WordPress that detects whether a user is visiting on a mobile device or not and allows to display content accordingly. It is quite handy function for those willing to include a bit of code for only mobile users.

[php]
<?php if( wp_is_mobile() ) : ?>
Visit our website on your desktop for a richer user experience
<?php endif ?>
[/php]

Clean_url

This function was recently replaced by esc_url and esc_url_raw. It takes a URL input to make sure it is structured correctly, and if not – to fix it. To be specific, in case http:// is missing, it will be added to the front of a URL. There is a plenty of use cases, so the function is worth to be paid attention to.

[php]
function clean_url( $url, $protocols = null, $context = ‘display’ ) {
if ( $context == ‘db’ )
_deprecated_function( ‘clean_url( $context = \’db\’ )’, ‘3.0’, ‘esc_url_raw()’ );
else
_deprecated_function( __FUNCTION__, ‘3.0’, ‘esc_url()’ );
return esc_url( $url, $protocols, $context );
[/php]

Conclusion

These are just a few of WordPress functions that are waiting for you to use them. Get ready for a set of new functions to be discovered in the nearest future.

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

P.S. Willing to take your web project a step forward with WordPress? Then look no further than CMS2CMS automated migration service and become a part of WordPress glory right now.