15 WordPress hacks you can do without plugins

One of the things I love about WordPress is the easiness to empower it with (almost) endless features thanks to plugins. With 38000+ free plugins and an uncountable number of premium and custom ones, there’s a WordPress plugin for every need and budget. And if you look online to get WordPress tips, tricks or hacks, you'll surely end on a blog post that’s covering a list of (great) plugins that will provide you with what you were looking for. Actually, it's quite difficult to find a great list of WordPress tips, tricks and hacks that doesn't count a plugin in it.

I know, they are powerful tools, but plugins aren't always required to enable a specific feature because WordPress alone can do cool things too.

So my question is: how many interesting features can be enabled on a WordPress website without installing a single plugin? I've put together a list of the best WordPress code snippets (or WordPress hacks, you choose) that you can play with right away and see for yourself you don't always need a plugin.

The following piece of codes can break your website, so please pay attention and make a backup before getting your hands dirty with them.

WordPress Code Tweaks: Admin and dashboard

Change the login logo with yours

Let's start with one about branding: if you ever wanted to change the WordPress logo on the login page with yours (or a client's), that's the code you'll need. It's easy: just open your functions.php file and paste the following:

Reinforcing your brand communication with this little tweak is just the first step, you'll see how many things you can do without installing plugins. [via]

Change the admin logo

Have you ever wanted to "feel" the WordPress dashboard closer to your business? How about featuring a new client's logo in there? That would be cool but installing a new plugin just for that sounds like too much. How about I tell you can do this with no plugin at all? Open the functions.php file and paste this:

You now should put your logo in the wp-images folder and call it admin_logo.png. [via]

Disable WordPress Login Hints

Keeping your WordPress website secure is important (see how to improve it), and there's a little thing that will make a hacker's life more difficult: not providing detailed error messages on the WordPress login page. To disable these warnings you need to open your functions.php and copy this:

This way you no longer provide useful hints that could be exploited for malicious activities. [via]

Keep logged in WordPress for a longer period

When you work on public wi-fi networks, or not on your computer, it's always good practice to log out from those devices. But when you're on your home network and your computer, getting kicked out after a while might be annoying to some. How about extending the time of your WordPress login session? This code will do the trick, just open the functions.php file and copy it:

By the default, WordPress will keep you logged in for 2 weeks when you check the "Remember Me" option at login. You can set the expiry date of the authorization login cookie by replacing the "31556926" with your preferred time span. [via]

Replace "Howdy" with "Logged in as" in WordPress bar

If the default "Howdy" is too informal or you just want another message on the WordPress menu bar, head over to your functions.php and add this:

You just need to insert your new message as the 2nd element within the $newtitle array, and you're done. [via]

Change the footer text on WordPress dashboard

Branding is about messaging and consistency. So if you're building up a website for a client, you'd want them to feel happy about what you did and feel important too. So, besides having their logo on their login page and dashboard, how about adding their tagline or some cool text on the dashboard footer too? Cool, just open up the functions.php file and go with this:

Now it's all about your creativity to impress them, make them smile, or even quote some motivational words. [via]

Add a shortcode to widget

Shortcodes are super-useful because they can just replace what that could be a long piece of code with a little line between square brackets. By default, WordPress widgets aren't enabled to manage shortcodes and they handle them like regular text. But there's the possibility to empower WordPress widgets with the ability to use shortcodes as well thanks to the following piece of code added in the functions.php file:

add_filter('widget_text', 'do_shortcode');

This code tweak will make you take advantage of shortcodes on other great tools WordPress comes with: widgets. [via]

WordPress Code Tweaks: Posts and Pages

Require a featured image before you can publish posts

Publishing a blog post or a page on WordPress is easy but in many cases words alone aren't enough: news, product pages, etc. they all need images to stand out and communicate better. So how about making it mandatory for your users to add a featured image to their post or page unless they aren't able to publish it? Great, open functions.php and apply the following code:

Isn't this useful? Of course, you can set your custom alert message by editing whatever fits your needs. [via]

Reduce Post Revisions

Revisions are the WordPress built-in time machine to the edits of your content. By default, there's no limit to the number of post revisions that are stored in your database, but "infinite" is a huge number that hardly would be useful to the purpose of your website. That's why you can set a specific number of revisions you want to be saved. For this tweak, you should open the wp-config.php file and add:

define( 'WP_POST_REVISIONS', 3 );

Pick a number that works for you and put it in it. If you want to disable the storage of revisions (and just have the autosave), use "-1" instead.[via]

Delay posting to my RSS feeds for 60 minutes

Imagine this: you just published the latest post on your blog and the RSS feed is already sending it to your subscribers, when you see there's a typo in the headline. That's a bummer, if only you had some more time to check everything out better... With this piece of code you can! Specifically, you delay the posting to your RSS feeds so you'll have enough time to check for the last time. If you like the idea, open the functions.php file and add this:

Tweak the "return 20" line by adding the number of words you'd like to be shown in your excerpts. Remember: the WordPress default value for excerpt length is 55. [via]

Change the post auto-save interval

The auto-save feature is your safety net: automagically WordPress saves your work, so you don't have to worry about it in the event of a browser crash or a blackout. For some users though, the 1 minute default could be a little too much and they keep interrupting their work to push the save button. For these little crazy monkeys (count me in), it'd be great to decrease the time span between auto-saves without a plugin. And this is easily achieved by adding the following code to the wp-config.php:

define( 'AUTOSAVE_INTERVAL', 45 );

Of course the code tweak works the other way around, so if you want to increase the auto-save interval, just set a higher value like 120 seconds or even more, you adrenaline junkies :D.[via]

WordPress Code Tweaks: Search

Show the number of results found

Search results pages are important for a website UX, so it should be pretty useful to the user. Problem is many search results page give no information about how many pages on what I'm searching for there are in a website. Thanks to the following line of code in your search.php file, you'll be able to show how many items are related to that search:

This way a generic and uninformative title such as "Search Results" becomes a valuable one by providing the exact number of articles related to the search like "Search Result for search terms – 12 Articles". [via]

Exclude categories from search

If you want to have a deeper control over the results users can get, you might need a way not to show specific categories within the results page. The use cases are endless: promotional material, press release, translated content, portfolio items, just to name a few. Interested in how to do that? Open your functions.php file and add:

Wrapping things together

See? No need to install new plugins and you "earned" 15 neat features to test and, if you like them, implement directly on your website or on your clients'. The point here is, even if it's easy and there's no backfire in installing a new piece of software anytime you want, plugins can quickly pile up and make your website clunky in the future for many reasons. So you might want to pay attention to install just those that are crucial to your website or business.

I know this list is far from being exhaustive, and we'd love to hear from you: what WordPress tweaks would you add to this list? What features can be quickly and easily enabled on WordPress without a plugin? Share your thoughts and knowledge here in the comments!

Every one of those would make way more sense to put into a plugin so it would survive a theme change.

There are even plugins in the directory now to help create a custom functionality plugin for those that are intimidated by creating a plugin of their own. I wouldn’t recommend them, but I’d recommend that over dump all this into a theme functions.php file.

Hey Jon, Good point here. Just want to say, the goal of my post was to show some (of the many) useful features users can enable by directly adding code to a WP website. This is far from being a “best practice” article, nor it was intended in the first place. Your feedback is a great topic for a follow-up article (together with Bruno’s). Thanks for sharing it!

Or add them to your mu-plugins folder. I’ve been using a lot of these “hacks” for years. Because they’re simple, and I want them to always run, I keep them in the must use folder: https://codex.wordpress.org/Must_Use_Plugins

For example, if I wanted to run all the hacks in this post, I’d create a new file: myhacks.php; then add all the snippets in to that file; then save it to mu-plugins. That’s how easy it is.

Since these are easy customizations you’d want to use on any/all your WordPress installs, it’s as easy as adding your myhacks.php file to those installs.

I wouldn’t put sitewide hacks like this in mu only because personally I’d like to be able to deactivate them when debugging, BUT you might want to checkout an mu plugin I’m working on with a friend: https://github.com/joeguilmette/wp-local-toolbox

It’s really geared towards developer hacks for local/staging environments, some of which (disable plugins) need to run before standard plugins, but it’s turning into a nice framework for extending as you see fit.

Bill Dyszel

There are situations, in large organizations, for example, when corporate IT policy forbids plugins and you have no control over the policy. This kind of information is helpful.

Dee see

Do you mean, if i have means of implementing all my installed plugins into my function.php file, is a best option? Please prof. can you explain precisely, what are the main advantages of using function.php file for more functionalities in WordPress instead of installing plugins?

If you would have spent 5 mins more writing this article and making all the code used much more consistent, the article would have been so much better!

You should ALWAYS prefix code snippets with something unique, for example your initials. Instead you copied the code snippets verbatim from their sources, which means that sometimes they come with prefixes and sometimes not at all.

You could also have spent some time properly internationalising your code to make the snippets more useful for the other 60% (or more) of the people that use WordPress in another language than English…

Natalie

Regarding Excerpts, is there a way to enforce them to respect paragraphs and other formatting?

One plugin I use on all my sites is WORDFENCE – free security plugin. Does a nice job. I am amazed at how many notices I get of people trying to get into my sites. To me, Wordfence and iTheme Security are must haves on all sites.”

I installed anti spam plug in that you recommended and in the last few days I have no spam in my folder to get rid of. This is great, as I was constantly emptying my spam folder, and now I can devote my time to other things. Thanks so much for the tip. I will be trying others…..