5 Useful WordPress Hacks for Better Themes

wp-theme-hacks

WordPress has evolved a lot from a simple blog system to a great CMS (Content Management System) with tons of cool plugins and functions that make your work simpler. Howver the most powerful controller is your theme. No matter you have so many plugins right from breadcrumbs to comments follow back, these plugins may only work if you theme is smart enough to deal with them.

These snippets are for all those theme developers who want some “more” with their theme.

How to Add an Automatically Changing Copyright Year in Your Footer

Copyright &copy; 200x-<?php echo date('Y'); ?> Example.com.

How to Close Comments on Posts Older than 1 Month

<?php
function close_comments( $posts ) {
	if ( !is_single() ) { return $posts; }
	if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( 30 * 24 * 60 * 60 ) ) {
		$posts[0]->comment_status = 'closed';
		$posts[0]->ping_status    = 'closed';
	}
	return $posts;
}
add_filter( 'the_posts', 'close_comments' );
?>

How to Disable Indexing of Pages by Search Engine

<?php if ( is_category('4') || in_category('4') ) {
    echo '<meta name="robots" content="noindex">';
}

How to Display the Total Number of Posts on Your Blog

<?php $numposts = $wpdb->get_var("SELECT count(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'");
if (0 < $numposts)
     $numposts = number_format($numposts);
echo $numposts.' posts.';
?>

How to Display Widgets wrapped in DIV tags instead of LI tags

if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'name' => 'leftbar',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div><!--/widget-->',
        'before_title' => '<h3 class="hl">',
        'after_title' => '</h3>',
    ));

Related posts:

  1. How to display Posts with most Comments
  2. How to Insert content after each post in WordPress
  3. How to make your WordPress Theme Widget Ready
  4. How to create a WordPress Theme
  5. How to Create a WordPress Plugin – Hello World!


The author is a small business owner himself specialising in Web Development. He runs Insight Studios which offers specialized Web Development, SEO Services and PPC Management for Small Business and SME thus ensuring growth and prosperity using the power of social media.

Share This Post

Related Articles

Leave a Reply

© 2012 MyGeekPal. All rights reserved. Site Admin · Entries RSS · Comments RSS
Designed by Insight Studios