Cool WordPress Hacks You Can Do Without Plugins

Top hacks for Wordpress

The thing we like the most about WordPress here at Siamcomm is how easy it is to empower the platform with endless new features, all thanks to the plugins that are available. There are around 38,000+ free plugins available and thousands more premium ones available. There is practically a plugin available for everyone’s needs as well as budget. If you decide to take a look online for tricks, tips or hacks relating to WordPress, you will no doubt end up on an article which covers a list showing popular plugins which will give you exactly what you are looking for.

In fact, it is quite hard to find blog posts on WordPress hacks which don’t include any plugins in it!

Plugins are very powerful tools, however, they are not always needed to enable specific features because the WordPress platform can do some pretty amazing things by itself.

So the question is this: How many cool features can you enable on WordPress without the use of any plugins? Below is a list we have put together that show you the best code snippets (or hacks, you can choose) which you can start playing with straight away and find for yourself that you do not always need to use plugins.

Please Note: The following code inputs may break your website. Please make a backup before you start testing them for yourself.

Admin and Dashboard Code Tweaks

Replace the login Logo With Yours

Let us start with a branding WordPress hack: Have you ever wanted to replace the standard WordPress logo on the sign in page with your own or a client’s? Here is the code you need. Just paste the following to your functions.php file:

 

1
2
3
4
5
6
7
8
9
10
11
function my_custom_login_logo() {

echo '<style type="text/css">

h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }

</style>';

}

add_action('login_head', 'my_custom_login_logo');

 

Reinforcing your brand communication is just the first tweak that you can do without the need for installing plugins.

Changing the Admin Log

Would you like the WordPress dashboard to resemble your business more closely? Or maybe you would like to feature one of your client’s logos in there? It would be awesome right? But installing a plugin just to do that sounds a little bit too much. So what about if you could do it without the need for a plugin at all? Well you can. Just open the functions.php file and paste the following:

 

1
2
3
4
5
6
7
8
9
function my_custom_login_logo() {

echo '<style type="text/css">

h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }

</style>'; }

add_action('login_head', 'my_custom_login_logo');

Now you need to place your logo of choice into the wp-images folder and name it admin_logo.png and that’s it!

Disable the WordPress Login Hints

It is very important that you keep your WordPress site secure. Fortunately there is one thing that can help to make a hackers life a little more difficult: Not providing any detailed error messages on the login page. You can disable these warning messages by copying the following code and pasting it into your functions.php file.

 

1
2
3
4
5
6
7
function no_wordpress_errors(){

return 'GET OFF MY LAWN !! RIGHT NOW !!';

}

add_filter( 'login_errors', 'no_wordpress_errors' );

By doing this you will no longer show any useful tips and hints that may be exploited by a hacker.

Stay Signed in to WordPress for Longer Periods

If you are working in a public place and using a public wi-fi network, or using a different computer, it is always best practice to log out after your session. But when you are using your own home network and your own computer, being thrown out after a while can get pretty annoying. So, how about extending your login session time by placing the code below into your functions.php file:

 

1
2
3
4
5
6
7
add_filter( 'auth_cookieIf_expiration', 'stay_logged_in_for_1_year' );

function stay_logged_in_for_1_year( $expire ) {

return 31556926; // 1 year in seconds

}

By default, you will be kept logged in for 2 weeks once you have checked the “remember me” option when you log in. You are able to change the expiry date of the authorization cookie; just replace the “31556926” with the time span of your choice.

Replace “Howdy” with “Logged in as” in the WordPress Bar

If you dislike the “Howdy” message on the WordPress menu bar, or it is just too informal for you, head to your functions.php file and add the following:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function replace_howdy( $wp_admin_bar ) {

$my_account=$wp_admin_bar->get_node('my-account');

$newtitle = str_replace( 'Howdy,', 'Logged in as', $my_account->title );

$wp_admin_bar->add_node( array(

'id' => 'my-account',

'title' => $newtitle,

) );

}

add_filter( 'admin_bar_menu', 'replace_howdy',25 );

Just type your new message as the 2nd element in the $newtitle array, then you are done.

Replace the Footer Text on the WordPress Dashboard

Branding is all about communication and consistency. If you are in the process of building a new website for a client, you will want them to feel pleased about what you are doing for them. So instead of just adding their company logo to their dashboard and login page, why not add their tagline or cool text on the footer in the dashboard too. Cool right? Just go to the functions.php file and type the following:

 

1
2
3
4
5
6
7
function remove_footer_admin () {

echo "Your own text";

}

add_filter('admin_footer_text', 'remove_footer_admin');

Be creative here so that you can impress your client and make them smile!

Add a Shortcode to Widget

Shortcodes are a very useful tool to use as they are able to replace what may be a long piece of code with a short line between brackets. By default, WordPress widgets are unable to handle and manage shortcodes like regular text. However, the good news is that you can empower widgets with the ability to make use of shortcodes by adding the following piece of code into the function.php file:

 

1
define('widget_text', 'do_shortcode');

 

This small tweak to the code will allow you to take advantage of using shortcodes on widgets

WordPress Code Tweaks: Pages and Posts

Reduce Post Revisions

Revisions are the edits of your content and these are stored in your database by WordPress’s own built-in time machine. There is no maximum number of revisions that can be saved and stored, but soring huge numbers of revisions is unlikely to be useful to the purpose of your site. Fortunately you are able to set a specific number of revisions that are saved to the database. To do this tweak you will need to open the wp-config.php file and type the following:

 

1
define( 'WP_POST_REVISIONS', 3 );

Just choose a number which works for you and replace it with the 3. If you wish to completely disable the storage of revisions and have them autosave instead, just add “-1” instead.

Delay my RSS Feed Posts for 60 Minutes

There may come a time when you publish the latest blog post on your site and after a few moments you notice that there are typos in the article. This is a bummer when your RSS feed has instantly sent it to your subscribers. If only there was a little time for you to double check everything before your subscribers receive it. Fortunately there is! With the following code you can delay the posting to your RSS feeds for up to 60 minutes. Open the functions.php file and enter the following:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Delay_RSS_After_Publish($where) {

global $wpdb;

if (is_feed()) {

$now = gmdate('Y-m-d H:i:s');

$wait = '60';

$device = 'MINUTE';

$where.=" AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";

}

return $where;

}

 

add_filter('posts_where', 'Delay_RSS_After_Publish');

This is very useful for allowing time to make final checks and ensure there are no typos or any broken links. You can edit the “60” with a number that better suits you.

Change the Post Interval for Auto-Save

WordPress is great in that it auto-saves your work so you do not need to worry if your browser crashes or there is a power cut. For some people using WordPress though, the 1 minute default can be a little too much and they have to keep interrupting their work to click on the save button. It would be great if you could decrease the time span in between auto-saves without the need of a plugin. Well you can. Add the following code into the wp-config.php file:

 

1
define( 'AUTOSAVE_INTERVAL', 45 );

This also works the other way round, so you can also increase the interval between auto-saves. Just change the “45” above to whatever suits you.

Code Tweaks for Search

Show the Number of Results Found

Search Result pages are vital for a websites user experience and useful to the user. The problem is that many search result pages give absolutely no info about how many pages there are in a website related to what I’m searching for. By using the following code you are able to show exactly how many of the items are related to your search. Add the following to your search.php file:

 

1
<h2 class="pagetitle">Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2>

By doing this, generic and uninformative titles become valuable by providing the exact amount of articles which are related. For example “WordPress Hacks” – 10 articles.

Excluding Categories From Search

Do you want to be able to have more control over the results that users are able to get? If so you may not want to show certain categories within the results pages. The use cases are endless: Press releases, portfolio items and translated content are just a few. If you want to do this then just add the following to your functions.php file:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
function SearchFilter($query) {

if ( $query-&gt;is_search &amp;&amp; ! is_admin() ) {

$query-&gt;set('cat','8,15');

}

return $query;

}

add_filter('pre_get_posts','SearchFilter');

By having the ability to exclude certain categories from your results page, you will be able to improve the quality of info that you deliver to your readers.

Exclude Whole Pages from Search

The same thing goes for any pages that you wish to keep from being shown in results. Just add the following code to your functions.php:

1
2
3
4
5
6
7
8
9
10
11
function modify_search_filter($query) {

if ($query-&gt;is_search) {

$query-&gt;set('post_type', 'post');

} return $query;

}

add_filter('pre_get_posts','modify_search_filter');

This can be used on your blog to allow users to just browse and search for your single posts, missing out all the pages that they have no interest in.

Wrapping it Up

See? There is no need to install any new plugins to make any of the changes listed above. Very cool right? It might be easier to just find and install a simple plugin but plugins can quickly pile up and make your website slow and clunky. So you may want to only install the ones that are crucial to running your website.

Hopefully the above list is not too exhaustive. We would love to hear any comments that you may have, or any additions you would like to see in the above list.

 
 
 
%d bloggers like this: