Filed Under: Wordpress Code

14 Tricks to Make Your Theme Better

Wordpress tips and tricks

WordPress is a very powerful CMS (Content Management System). It has tons of capability and can be extremely powerful. There’s only one thing in the way from all of this power and you as the blog owner – your theme. See, no matter how many awesome features such as threaded comments or breadcrumb navigation or even an “edit” link beside each post are added, you’re limited by your theme that you are using. If you theme isn’t “smart” enough to use these features, well, quite frankly, you can’t use them.

This is a post for all the WordPress theme developers out there. Here are only a few of the many great snippets of code that will take your current theme creation and make it that much better. Please, use them.

1- How to Disable Commenting on Posts Older Than 1 Month
A great way to reduce the amount of spam you receive is to disable the ability to comment on posts that are more than 1 month old. Just paste the following in your functions.php file. Note: To change the amount of time from 1 month, just replace 30 (days) with any number of days you want.

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' );
?>

2 – How to Add an Automatically Changing Copyright Year in Your Footer
This is a common sight on most sites, something like a “Copyright 2007 – 2009″ or something similar in the footer. Thing is, it’s been more than a month since the new year and yet I’m still seeing “2008” as the current year on some sites. This is how you can make WordPress change the date for you. Put in this snippet of code wherever you want the dynamic date to be displayed.

Copyright © 200x- Example.com.

3 – How to Display a List of Allowed HTML Tags for Use in Comments
Ever been to a blog where you’ve seen a list of all of the allowed HTML tags right above the comment form? Ever wonder how to do that in WordPress? Well, wonder no more.

You may use: .

4 – How to Add an “Edit” Link Next to Each Post
Ever see an error in one of your posts and sigh at the fact that you have to now go an navigate through the WordPress Dashboard just to get to the post to edit it? Not anymore. Just add this next in single.php, index.php, or wherever a post appears. Note – Only admins can see the edit link.

5 – How to Remove Curly Quotes From Your Posts
Ever copy and paste some php code you found on a website and find out that all of the quotation and apostrophe marks were causing errors? This is because of the way WordPress styles these punctuation marks to make them more aesthetically pleasing. Who needs that, right? Just paste this code into your functions.php file and you’re good to go.

6 – How to Remove Curly Quotes From Your Comments
Same thing as above, only this time, the code removes the curly quotes from your comments instead of posts.

7 – How to Disable Search Engine Indexing on a Certain Category
This code snippet is more for SEO purposes, possibly to avoid duplicate content or something similar. Make sure search engines don’t index any posts in a certain category by applying this to your head tags in header.php. Note – Change the category number of 4 to the category you want to prevent search engines from seeing.

';
}

8 – How to Display the Total Number of Posts on Your Blog
A useful code snippet that displays how many posts you’ve made.

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.'; ?>

9 – How to Add a Simple “Tweet This” Link to Each Post
Twitter is getting more and more popular each day. To make this benefit you, why not add a nice little “Tweet This” button to each blog post? Put this somewhere in The Loop in single.php.

Tweet This!

10 – How to Display Your Scheduled Posts
Scheduling your posts in WordPress is a great feature. Create a sense of suspense for your readers by allowing them to see the title’s of upcoming posts. Paste this anywhere in your theme files.

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

11 – How to Exclude Certain Categories From Being Shown
If, for whatever reason, you don’t want certain categories to be displayed, paste this code into The Loop. Note – Replace “3” with the number corresponding to the category you want to block.

12 – How to Allow Styling of Individual Posts
This is a pain when themes don’t have this built in. If the user of your theme wants to style a single post differently than all of the others, the only way for you to make this easy for them is by giving each post a unique identifier. To do this, simple make use of “the_ID” in The Loop.


13 – How to Add a Unique Identifier to Each Comment

This basically follows the same idea as above, only now it’s applied to comments.


14 – How to Separate Trackbacks / Pingbacks and Actual Comments

The comment area of your posts should be a place where your readers can talk and discuss things with you and eachother. It’s annoying if this discussion is interrupted by a few trackback announcements. Tidy up the comment area by putting the comments in one pile and the trackbacks in another.




Genesis Framework for WordPress

Reacties

  1. Your own article, “14 Tricks to Make Your Theme Better
    | ThemeBuilder” ended up being truly worth commenting here!
    Basically wanted to announce u really did a great work.
    I appreciate it -Mavis

  2. bedankt voor de wp tips!

  3. Mooie post. De geshi highlighting doet wel wat gek onder puntje 14.
    Wordpress is onuitputtelijk. Het is leuk om te zien hoe een blog geoptimaliseerd kan worden. Vooral die scheduled posts lijkt me wel wat. Je hebt je net een feedreader bijverdiend met deze post. ;)

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *

De volgende HTML-tags en -attributen zijn toegestaan: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>