Categories: WORDPRESS

10 Useful WordPress Functions You Probably Not Know

Today in our article we are going to explain you some of the useful features of WordPress which can be useful to develop websites with this CMS. Many of these features will help us to use WordPress as more than just a CMS, with which we can develop web applications.

These s go along with any plugin or theme that we develop. Surely you do not know most of the following s and probably the next time you go to develop something you will save a lot of codes for using any of these s. Let us start:

 

Get Unique File Name

If we want to save a file in a directory we must ensure that there is no longer the same name. WordPress has the wp_unique_filename () to pass it a directory and filename. This checks that the file exists and if there will add a number to the end ensuring that there is no such file.

$ Nombre_archio = wp_unique_filename ($ directory, $ filename);

Shows the Size of a File

This plugin is ideal for working with images or videos. These types of plugins are helpful to calculate the size of the files. WordPress gives us size_format () to which we pass the size in bytes and it is about showing the size of the best. For example

size_format (1024) / / will return 1kb

size_format (1048576) / / will return 1 MB

Displays the Relative Time Format

This may be personal, but I do not like the type dates 13/05/2013 10:30 AM. Since I believe that the users don’t find anything through it. Prefer a relative time rate such as posted 3 days ago. WordPress has a that is human_time_diff () that transforms us the date to this format automatically.

human_time_diff ($ from, $ to = NULL);

Check If User is Mobile

This is really useful. WordPress has a in PHP that allows us to detect whether or not the user comes from mobile.

if (wp_is_mobile ()) {

echo “from the mobile user”;

Else {}

echo “User from desktop”;

}

Change the HTTP Status Code

For example, if we take the user to an error page, instead of using the default WordPress s, we can use status_header () as follows:

status_header (‘404 ‘) / / 404 error page

Encodes to Avoid Spam Emails

There are many robots that are dedicated to surf the web pages looking for email addresses for later mind add to a database and send spam. With WordPress, using the antispambot () can encrypt emails to print them on screen without robots that can scan them.

$ Email_codificado = antispambot ($ email);

Make clickable Links

WordPress comes with this feature that will turn our planes links clickable links below. Example:

$ String = “I’m reading http://guiabreve.com”;

miss make_clickable ($ string);

/ * Will print: I’m reading <a href=”http://guiabreve.com”> http://guiabreve.com </ a> * /

Make your own Slugs

WordPress uses a feature called `sanatize_title_with_dashes () ‘to generate all the slugs. We can use this whenever we find it useful.

/ / Will print: this-is-a-title

Sanatize_title_with_dashes miss (“This is a title”);

Are we in SSL?

WordPress also gives us simple to check if right now you’re using the SSL protocol.

if (is_ssl ()) {

echo “We are in SSL mode”;

}

Cut a String by Number of Words

We can use this to generate our own excerpts or summaries of a string. A wp_trim_excerpt () we pass the text to be cut and the number of words we want the resulting string.

$ Excerpt = wp_trim_words ($ text_largo, 100) / / 100 words

Mohan

I'm Mohan From Hyderabad was born on 05-May-1998 . I'm a Young Blogger and an Entrepreneur. Blogging Since 2015. Away from Blogosphere, I love listening music and hangouts with friends.

Share
Published by
Mohan

Recent Posts

Should you convert from prepaid to postpaid? What are the benefits?

In an age where staying connected is paramount, choosing the right mobile plan can be…

8 months ago

Do You Need a Disposable Mobile Number for Verification?

Disposable phone numbers are here to stay and there are many reasons why. Stay with…

2 years ago

The Benefits of IT Consultation Services

The benefits of IT Consultation Services are numerous. Not only do they help businesses find…

2 years ago

The Perfect Mobile Plan for Your Situation

Thankfully, roaming charges are a thing of the past when you go to France for…

2 years ago

What Is an IP Phone System? Does My Business Need One?

All business owners are doing their best so their business continues to grow. With proper…

2 years ago

Getting A Lån: 4 Tips For Choosing A Lender

Have you been thinking a lot about finding a way to gather the money that…

2 years ago