/12 functions.php Useful Functions
functions.php tips

12 functions.php Useful Functions

Those of you that have dug around the WordPress website structure a bit or if you are even very familiar with the WordPress file structure, you must know that one of the few mandatory files is the famous functions.php file. WordPress cannot run a site without a functions.php file.

The functions.php file is used for various tasks such as:

  • Adding fonts
  • Adding scripts
  • Getting a parent theme’s style
  • And much more…

The functions.php file can be looked at sort of like a plugin. You can add all your php functionalities in it, however, unlike a plugin, the functions used in it will be recognized in the current theme while a plugin is recognized on any theme you might add to your website.

So, seeing how there is literally no limit to tricks and functions you can add to the functions.php file, here are some favorites to get you started.

1. Remove WordPress Version from Links

Many spammers look for WordPress installations that print out the WordPress version they use. It is a good idea to stop using it. There are manual ways to do it, however you can just head over to your functions.php file and paste this function:

2. Change the WordPress Admin Footer Text

Sometimes if you are building a website for a client, you want to go the extra mile and show that you are better than anyone he ever worked with before. One of the ways to do that is to notice the small details that others don’t. A great example of that is to add a custom footer in the WordPress admin. The default footer reads: “Thank you for creating with WordPress.” But I like to change that message for clients and change it to: “Created by ____”. That can go a long way. Here is how it’s done. Add the following to your functions.php file:

You can even add a parameter in the link in order to track clicks in your Google analytics to see if it helps you get some of your previous clients’ traffic.

3. Add a Custom Widget in the WordPress Dashboard

You see these all the time. Lots of plugins add custom widget messages in your dashboard and lots of the themes do that too. Now, so can you. What I like to do is add a custom message meant for my client. This is how I do it:

Add the above 2 functions to your functions.php file, change the text to fit whatever you want your client to see and refresh your admin dashboard page. This is what it should look like:

wordpress admin dashboard widget

4. Add a New Menu to Your WordPress Theme

Some themes come with 1, 2 or 3 navigation menus, say header, footer and social icon menus. But what if you want to add a new custom menu to the sidebar? How can you do that? Luckily enough it’s pretty simple, lets add the following code into our functions.php file:

We just registered a menu “location” and you will be able to see it on your menu page in the admin. It will look something like this:

wordpress menu

Now all you have to do is create a new menu on that page and set its location to “sidebar menu”.

The last thing you need to do is paste the following code where you want the navigation menu to appear (on your sidebar using my example):

5. Add New Widget Areas in WordPress

You know how you have themes that have widget areas that you can control from the widget page? They usually look similar to this:

Wordpress widget areas

Well, now you are going to create one yourself. Head over to your functions.php file and paste the following:

If you refresh your widgets page you will now see a new widget area where you can drag any of the available widgets to. In order to actually use whatever you plan on adding to that widget, go to your footer.php file (just an example because we called the widget special footer text) and print the following where you want to see the widget:

 

6. Disable WordPress’ Built-in Search

There are lots of websites that do not need WordPress’ built-in search form, this is how you can remove the actual feature. Note: you will still need to remove the actual form if it’s built in to your theme:

7. Change the Read More Text in WordPress Excerpt

I’ve probably had to do this change on over 50% of the websites I’ve built. WordPress excerpt has a default “read more” text which doen’t always fit what you want to use. In this example I changed it to “…”(three dots), feel free to change it to whatever you want. Just add the following to your functions.php file:

8. Change WordPress’ Excerpt Length

Continuing with WordPress’ built-in excerpt – how about changing its length? WordPress excerpt is usually used for the short version of blog posts on blog index pages / category pages / tag pages etc. You usually see the featured image, title, link and excerpt with 55 words. What if I want to show 70 words? Let’s do just that. Paste the following into functions.php:

9. Remove WordPress Admin Bar

Sometimes when editing a site and being logged in, I don’t want to see the black admin bar at the top of the page. There is a very simple solution for that. Paste this in functions.php:

Done 🙂

10. Remove the Default “Welcome to WordPress” Widget

If that annoys you like me, just paste this in functions.php:

11. Upload More Types of File Types in WordPress

If you ever tried to upload an SVG file as a logo, you know what this is all about. By default WordPress only allows a few types of files to be uploaded to the media folder. Though, you can easily change that if you need to by pasting this into functions.php:

If there is a certain mime type that you want to add that isn’t SVG then just google the mime type and add another row with the correct name right above the return row.

12. Add a Custom Login Logo

This is another one that shows your client that you went the extra mile. Instead of showing the default WordPress logo when your client logs in to hos website, lets show him his logo instead. Add the following to the functions.php file:

Now all you need to do is create a folder called “img” and add a “logo.jpg” file, then go to your login page and see what it looks like.

 

Conclusion

These functions are incredibly useful, lots of websites can use most of the functions we used here. If you want to take your WordPress website building to the next level, these functions are definitely the way to start.

Good luck!

 

Join Thousands of Others and Never Miss a Post