How many interesting features can be enabled on a WordPress website without installing a single plugin? Given below is 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.

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:

[tabby title=”PHP”]

function custom_admin_logo() {

echo ‘<style type=”text/css”>

#header-logo { background-image: url(‘.get_bloginfo(‘template_directory’).’/images/admin_logo.png) !important; }

</style>’;

}

add_action(‘admin_head’, ‘custom_admin_logo’);
[tabbyending]

You now should put your logo in the images folder of your theme and call it admin_logo.png.

Disable WordPress Login Hints

Keeping your WordPress website secure is important, 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:

[tabby title=”PHP”]

function no_wordpress_errors({

return ‘GET OFF MY LAWN !! RIGHT NOW !!’;

}

add_filter( ‘login_errors’, ‘no_wordpress_errors’ );

[tabbyending]

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

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:

[tabby title=”PHP”]

add_filter( ‘auth_cookie_expiration’, ‘stay_logged_in_for_1_year’ );

function stay_logged_in_for_1_year( $expire ) { return 31556926; // 1 year in seconds }

[tabbyending]

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.

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:

[tabby title=”PHP”]

function remove_footer_admin () { echo “Your own text”; }

add_filter(‘admin_footer_text’, ‘remove_footer_admin’);

[tabbyending]

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

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:

[tabby title=”PHP”]

define( ‘WP_POST_REVISIONS’, 3 );

[tabbyending]

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.

Change the length of excerpts

For some scenarios, the default excerpts don’t fit the layout, so you need to change it accordingly. If that’s what you need, with your functions.php file opened, copy in it the following code:

[tabby title=”PHP”]

function custom_excerpt_length( $length ) { return 20; }

add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );

[tabbyending]

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.

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:

[tabby title=”PHP”]

function SearchFilter($query) {

if ( $query>is_search && ! is_admin() ) {

$query>set(‘cat’,‘8,15’); }

return $query; }

add_filter(‘pre_get_posts’,‘SearchFilter’);

[tabbyending]

With the possibility to exclude specific categories from your search results page, you’ll also improve the quality of the information you deliver to your users and readers.

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Request a Quote

Let our code do the miracles for your website

We are an award winning web agency with over 10 years of experience in web development. In the past, we have helped numerous businesses establish their online presence through clean and semantic code. Our dedicated team of developers ensure the success of your project by paying attention to detail and by going that extra mile with you until the results are achieved.

</ THEHTMLCODER.COM >

Copyright 2018 - THEHTMLCODER.COM