I enjoy developing themes for WordPress, but sometimes, It takes a lot of time to collect various snippets of code. Thus, I have tried to collect some code snippets that would help you while developing or editing your existing theme. If you have any code you would like me to add, please leave a theme as comment below!
Between <head> and </head>
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>><head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
<meta name="description" content="<?php wp_title(); ?>" />
<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats please -->
<style type="text/css" media="screen">@import url( <?php bloginfo('stylesheet_url'); ?> );</style>
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="<?php bloginfo('atom_url'); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php wp_get_archives('type=monthly&format=link'); ?>
<?php //comments_popup_script(); // off by default ?>
<?php wp_head(); ?>
</head>
A quick note to say; You could speed up your WordPress blog system by changing stylesheet, pingback and feed to static URL’s.
<li<?php if(is_home() || is_404() || is_single() || is_category() || is_day() || is_month() || is_year() || is_paged() || is_search() ) { ?> class="current_page_item"<?php } ?>><a href="<?php bloginfo('home'); ?>">Blog</a></li>
<?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
First snippet will display a text “blog” with a link to the main page and second snippet will print WordPress pages links in a list (excluding the child pages and title header for the list). The active link from the list will be assigned with “current_page_item” class.
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permalink to <?php the_title(); ?>"><?php the_title();
?></a></h1>
<?php the_content(__('...read on »')); ?>
</div>
<?php endwhile; ?>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
This is the loop that I use for my themes. You can customize class of div and <h1> tag as it would fit with for your theme.
<?php the_time('F j, Y'); ?>
<?php the_category(',') ?>
<?php the_permalink() ?>
<?php the_title(); ?>
<?php the_author(); ?>
<?php the_ID(); ?>
<?php edit_post_link(); ?>
<?php wp_list_cats(); ?>
<?php next_post_link(' %link ') ?>
<?php previous_post_link('%link') ?>
<?php posts_nav_link(); ?>
<?php posts_nav_link(); ?>
<?php wp_get_archives(); ?>
- Displays date and time. Format: January 21. 2007 More »
- Displays links to categories, each category separated by a comma (if more than one). More »
- Displays the URL to the post More »
- Displays or returns the title of the current post More »
- Displays the author of post More »
- Displays the ID of current post More »
- Displays a link to edit the current post More »
- Displays a list of Categories as links More »
- Displays a link to the next post More »
- Displays a link to the current post More »
- Displays links for next and previous pages More »
- Displays links for next and previous pages. More »
- All available monthly archives links displayed in an <li> Html list (by default). More »
<?php if ( comments_open() ) : ?><p>
<?php comments_popup_link( 'No comments yet', '1 comment', '% comments so far', 'comments-link', 'Comments are off for this post'); ?></p>
<?php endif; ?>
This snippet helps you to hide the paragraph elements <p></p> that contains the comments_popup_link when comments are deactivated in the Write>Post screen. Good for those who want enable/disable comments post by post. Must be used in the loop.
Including templates
<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php comments_template(); ?>
<?php include (TEMPLATEPATH . '/yourfilename.php'); ?>
You can split your document into different files such as sidebar.php, header.php, footer.php or yourfilename.php and include theme to your template by adding above lines to your document.
<?php get_archives('postbypost', 8); ?>
<?php bloginfo('rss2_url'); ?>
<?php bloginfo('comments_rss2_url'); ?>
<?php get_links('-1', '<li>', '</li>', '', '', 'rand', '', '', '5'); ?>
- Displays last 8 post titles
- Displays RSS url for entries
- Displays RSS url for comments
- Display 5 of your blogroll links in a random turn









i was really looking up for the script to speed up my wordpress …you did it for me and i am much thankful to you…
Good work :)