Blog Post

WordPress is the world’s most popular content management system (CMS) that powers 27 percent of the web. Some of the reasons why people prefer it so much despite the availability of other functional systems are numerous:

Last but not least, WordPress is awesome because you can customize and extend it in almost any way you want to meet your needs. You don’t even have to install any additional plugins for many of these tweaks. In fact, customizing your WordPress can be as easy as inserting a line of code.

Here are some hacks for you to help make WordPress easier to use.

#1. Show Related Posts without Plugins

Displaying related posts is a good idea to help visitors find useful information and stay on the site longer. Many bloggers don’t know that they can easily integrate this function by default and download yet another plugin that does that (and we know the dangers of having too many plugins).

Here’s a step-by-step instruction on how to do that.

Open the single.php file

Insert this code in the loop:

1

2

3

4

5

6

7

8

9

10

11

12

if($tags){

echo'Related Posts';

$first_tag=$tags[0]->term_id;

$args=array(

'tag__in'=>array($first_tag),

'post__not_in'=>array($post->ID),

'showposts'=>5,

'caller_get_posts'=>1

);

$my_query=newWP_Query($args);

if($my_query->have_posts()){

while($my_query->have_posts()):$my_query->the_post();?>

And don’t forget to save the file!

#2. Delete “Howdy” and Replace it with “Logged in as”

If you don’t like the default greeting “Howdy” and want to replace it with something else, follow these steps:

Open functions.php file

Paste the following:

1

2

3

4

5

6

7

8

9

functionreplace_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);

Save the file.

#3. Add a Shortcode to Widget

A shortcode is an awesome tool that allows being creative with little effort. As a developer, you probably use them often to create objects while avoiding long lines of ugly code, but does your site have them enabled by default?

You can do that by adding the following line to the functions.php file:

1

add_filter('widget_text','do_shortcode');

#4. Decrease the Number of Post Revisions

“WordPress is without a doubt the best for blogging, but making numerous revisions takes a heavy toll on our limited database space,” says Jimmy Duncan, an editor at Proessaywriting.

“Turning them off was a huge space saver.”

Indeed, WordPress allows endless revisions in one post, but this is certainly not helpful for your website because all of them require storage. If reducing the number of revisions makes sense to you, feel free to add this line of code to wp-config.php file:

1

define('WP_POST_REVISIONS',2);

Keep in mind that you can include any number in the code. Disabling the revisions altogether requires putting “-1” instead of “3” as in the example.

#5. Force Perfect Images

WordPress compresses images to 90 percent of the original, which means that there’s a slight decrease in quality. While this is not a problem for many people, professional photographers require maximum quality of their photos.

There’s a way to force 100% quality. Just do the following:

Open functions.php file

Paste the following code:

1

2

3

4

5

6

{code type=php}

add_filter(‘jpg_quality’,‘high_jpg_quality’);

functionhigh_jpg_quality(){

return100;

}

{/code}

Save file.

#6. Reduce the Chance of Hacking by Hiding Publicly Visible System Version

As a developer, you probably know that hackers exploit security shortcomings in older WordPress versions used by websites. (in fact, having an outdated version is one of the main reasons for hacking). Removing the publicly visible version thus makes perfect sense to reduce this risk.

Use this code to do that.

1

2

3

{code type=php}

{/code}

#7. Exclude Pages from Site Search

If for some reason you want to keep certain pages out of search results, you can insert this code to functions.php file:

1

2

3

4

5

6

7

8

functionmodify_search_filter($query){

if($query->is_search){

$query->set('post_type','post');

}

return$query;

}

add_filter('pre_get_posts','modify_search_filter');

#8. Display the Number of Results Found

This could be a way of improving your website’s user experience because knowing how many pages with search results were found may be useful to visitors.

And this is easily achieved by inserting this code to search.php file (change “5” to any number you want):

WPblog is a WordPress resource website that regularly publishes content covering WordPress themes, plugins, hosting, news and ecommerce. WPblog aims to educate WordPress users about the best WordPress products and best practices so that they can create amazing websites.