The Extraordinarily Useful WordPress Hacks You Probably Haven’t Used as Yet

Today almost every website is powered by WordPress, so as WordPress hacks. Here in this article, you will go to see some code snippets or hacks which user is required to implement on a website so that he or she can take their website in a right direction or in a direction they want to.

1. Enabling Shortcodes in Widget

The edges which we want for our website, Widgets never gave the same. They have considered as an indispensable part of almost every WordPress website and if a user wishes to enhance the features or look of the website then for this shortcodes are here. A filter can also be used for this.

add_filter( ‘widget_text', ‘do_shortcode' );

2. Move the Navigation menu to the Center

Move the navigation menu to the center, hack allows the user to realign the logo and to place the same at the center of the header so that it doesn’t look in such a manner that it is out of the place. And here presents a code to do this:

#navigation {

position: relative;

}

#main-nav {

clear: left;

float: left;

list-style: none;

margin: 0;

padding: 0;

position: relative;

left: 50%;

text-align: center;

}

.nav li {

display: block;

float: left;

list-style: none;

margin: 0;

padding: 0;

position: relative;

right: 50%;

}

.nav li.hover, .nav li.hover {

position: relative;

}

.nav li ul li {

left: 0;

3. Let Your RSS Feed Contain the Post’s Featured Image

If pictures are used in your posts, it always leaves a good impression on your audience and pushes them to read and forward or share the same in your circles. And when posts featured image can be used by you in your RSS Feeds, your reach to the post can be enhanced by making it visible clearly and to perform this task, the following code snippets are useful:

add_filter(‘the_content_feed', ‘rss_post_thumbnail');

function rss_post_thumbnail($content) {

global$post;

if( has_post_thumbnail($post->ID) )

$content= ‘<p>'.get_the_post_thumbnail($post->ID, ‘thumbnail') . ‘</p>'. $content;

return $content;

}

4. Display the Most Accurate and Current Copyright Date

Copyright is a very important part of the website as it contains large relevant information which is confidential too and thus any webmaster doesn’t want to be copied the same by any other randomizers on the internet. Thus, to display the copyright information correct with max accuracy and in synchronization with the current year is very essential. Here the code helps you to do some updating in the copyright information on the constant basis and that too automatically.

function comicpress_copyright() {

global$wpdb;

$copyright_dates= $wpdb->get_results(“SELECT YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate FROM $wpdb->posts WHERE post_status = ‘publish'”);

$output= ”;

if($copyright_dates) {

$copyright= “© “. $copyright_dates[0]->firstdate;

if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {

$copyright.= ‘-‘. $copyright_dates[0]->lastdate;

}

$output= $copyright;

}

return $output;

}

5. Set the Editor You Want to as Default

Most of the people have a habit of using HTML Editor as it very user-friendly instead of the Visual Editor so here it allows you to select the option with which you are comfortable and wishes to set as the default one.And to set the preferred editor as default, given hack is to be followed.

# Visual Editor asdefault

add_filter( ‘wp_default_editor', create_function(”, ‘return “tinymce”;') );

# HTML Editor asdefault

add_filter( ‘wp_default_editor', create_function(”, ‘return “html”;') );

6. Cast Away the Primary orTop Navigation

Canvas, in particular, has two navigation bars. One navigation bar is located above the header and it is thereby called the Top Navigation Bar. Then, you have the Primary Navigation that is located below the header. Now, whether you wish to use both or just ones is entirely your prerogative, on our end, we can show you how to remove them:

Primary Navigation can be gotten rid of by this code:

add_action( ‘init', ‘remove_canvas_main_navigation', 10 );

function remove_canvas_main_navigation () {

// Remove main nav from the woo_header_after hook

remove_action( ‘woo_header_after','woo_nav', 10 );

}

And to remove the Top Navigation, you will need this:

add_action( ‘init', ‘remove_canvas_top_navigation', 10 );

function remove_canvas_top_navigation () {

// Remove top nav from the woo_top hook

remove_action( ‘woo_top', ‘woo_top_navigation', 10 );

}