TOP 10 Most Useful WordPress Code Snippets and Hacks

wordpress snippets and hacks
I think WordPress needs no Introduction. It is most popular blogging platform in this World. What makes WordPress more special is that it is easy to customize and have vast amount of useful plugins.

Here is the top 10 most useful collection of functions and hacks to get even more from WordPress

1.How to Modify the WordPress Login Logo & Image URL Link:

function my_custom_login_logo() {
echo '<style type="text/css">
h1 a {
background-image:url('.get_bloginfo('template_directory').'/images/your-logo-image.png) !important;
add_action('login_head', 'my_custom_login_logo');
function change_wp_login_url() {
echo bloginfo('url');//OR ECHO YOUR OWN URL
function change_wp_login_title() {
echo get_option('blogname'); // OR ECHO YOUR OWN ALT TEXT
add_filter('login_headerurl', 'change_wp_login_url');
add_filter('login_headertitle', 'change_wp_login_title');

The above code Will allow you to easily modify the WordPress Login page Logo as well as the href link and alt text of this logo.

2.How to Load  jQuery from the Google CDN:

add_action( 'init', 'jquery_register' );// register from google and for footer
function jquery_register() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery',
( '' ), false, null, true );
wp_enqueue_script( 'jquery' ); } }

The above code will add jQuery script from Google CDN.It will be useful for reducing  delay of script loading time.

3. How To Remove the WordPress Version Info for Security:

// remove version info from head and feeds
function complete_version_removal() {
return '';
add_filter('the_generator', 'complete_version_removal');

The above Code Snippet will Remove the WordPress Version info from the Head section of the Webpage.

4.How Delay the public posting to RSS Feed:

// delay feed update
function publish_later_on_feed($where) {
global $wpdb;
if (is_feed()) {
// timestamp in WP-format
$now = gmdate('Y-m-d H:i:s');
// value for wait; + device
$wait = '10'; // integer
// add SQL-sytax to default $where
$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
}return $where;}
add_filter('posts_where', 'publish_later_on_feed');

The above WordPress code Snippet will be very useful for delaying post to your RSS feeds for 10-15 minutes.

5.Automatically Add Twitter and Facebook Buttons to Your Posts:

function share_this($content){
if(!is_feed() && !is_home()) {
$content .= '<div>
<a href=""
<script type="text/javascript"
scrolling="no" frameborder="0" style="border:none;
overflow:hidden; width:200px; height:21px;"
    return $content;
add_action('the_content', 'share_this');

The above WordPress Code snippet will add Twitter and Facebook buttons to the bottom of all your posts. All you have to do is paste the code above into your functions.php file.

6. How To Add Breadcrumbs Without a Plugin in WordPress:

function the_breadcrumb() {
echo '<ul id="crumbs">';
if (!is_home()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo "</a></li>";
if (is_category() || is_single()) {
echo '<li>';
the_category(' </li><li> ');
if (is_single()) {
echo "</li><li>";
echo '</li>';
} elseif (is_page()) {
echo '<li>';
echo the_title();
echo '</li>';
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged']))
{echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';

Breadcrumbs is very useful in websites for navigation menus. It is also one of technique of Search Engine Optimization(SEO). Just Paste the above code into your functions.php file.

Then paste the following code to display the Breadcrumbs where ever in your theme files,

<?php the_breadcrumb(); ?>

7. How Add Content to the End of Each RSS Post in WordPress:

function feedFilter($query) {
    if ($query->is_feed) {
    return $query;

function feedContentFilter($content) {
    $content .= '<p>Extra RSS content goes here... </p>';

    return $content;

Just Paste the above code into the functions.php. Now you can add some extra content that is only viewable by your RSS subscribers.

8. How To Reset Your WordPress Password:

UPDATE `wp_users` SET `user_pass` = MD5('NEW_PASSWORD')
WHERE `wp_users`.`user_login` =`YOUR_USER_NAME` LIMIT 1;

In case you lost WordPress Admin Password and You can retrieve your password using your email Account.But if you have no longer access to Email account means, you need To Reset Your WordPress Admin password.

To fix this all you have to do is jump to your PhpMyAdmin Sql-window and run the above command.

9.How To Display Search Terms from Google Users:

If your site Visitor have reached your site via Google’s Search, then you can Greet the Visitor using above WordPress Code Snippet.

10. How To Include Custom Post Types in the Search Results in WordPress:


function searchAll( $query ){
  if ( $query->is_search ) {
 $query->set( 'post_type', array( 'site','plugin', 'theme','person' ));
}  return $query;
} add_filter( 'the_search_query', 'searchAll' );

The above code will include Your Custom Post Types in the WordPress Search Results page.

Raja CRN

Raja CRN is the Founder of CRN Interactive that offers various useful Digital Resources. He has more than five years of experience in content Writing and Web development specialized in WordPress. For the past 2 years, He is working on the Linux Administration. Occasionally, He dives into Android Development. He is an engineering graduate in Information Technology. He's also very social, find him at Google+

Copyright © 2009 -16 . SpicyTricks    Designed by ThemePacific