10 Code Snippets WP Theme Developers Should Have on Speed Dial

10 Code Snippets WP Theme Developers Should Have on Speed Dial

One of the ways we endeavor to improve productivity when building WordPress templates is to have snippets of code available to us very quickly, through the use of tab-triggered shortcuts. In this article I will share with you 10 of my most-used snippets that I feel every developer should have at their fingertips.


Coda tab-triggered shortcuts
Looking to take your coding speed to the next level?

As someone who builds a lot of WordPress themes from scratch 5 or more days per week, anything I can do to make my job less laborious or monotonous is a good thing! Repetitive tasks soon become overwhelming, and they can easily become the cause of a loss enthusiasm in a project, or indeed even an entire job.

Tab-triggered shortcuts are simply a series of user-defined keystrokes followed by a press of the TAB key. When you press the tab key, the text you typed prior to pressing the tab key is replaced with any text/code that you specify when you configure the shortcut. Tab-triggered shortcuts came to my attention through using Coda. However, this shortcut functionality is not exclusive to Coda.

A lot of text editing applications enable you to specify a sequence of key-presses to trigger a shortcut. Some examples include TextMate, E-TextEditor and Sublime Text. In fact, a lot of these applications allow you to download and add packages of code snippets that have been created for a similar purpose by other developers – saving you even more time! You could also achieve a similar effect by using something like TextExpander (Mac) or ActiveWords (PC) which is a background application that allows you to turn a few keystrokes in to anything you require – in any application.

So, without further hesitation, let me introduce you to 10 code snippets that I believe all WordPress theme developers should have on speed dial:

Note: You can obviously use any “shortcut” text that you prefer. I’ll share my own, but feel free to use other text to suit your own workflow.


1. Template Directory

Shortcut: tp[tab]

This snippet of code is used to return an absolute URL to the current theme directory. It is useful for embedding images and calling scripts, and should be use in place of typing a relative URL.

Code

	<?php bloginfo('template_directory'); ?>

Example

	<img src="<?php bloginfo('template_directory'); ?>/images/header.jpg" alt="Header" />
	<script src="<?php bloginfo('template_directory'); ?>/js/jquery.js" type="text/javascript">

2. Custom Query

Shortcut: query[tab]

This snippet of code places a custom WordPress query on your page. This is great for templates that have multiple queries running on them. You might use this for querying featured posts to render an image slideshow, or to simply display a list of news posts on a page or in the sidebar, as an alternative to widget functionality (as it’s more flexible).

Code

	<?php $query = new WP_Query(''); ?>
	<?php if($query->have_posts()) : ?><?php while($query->have_posts()) : $query->the_post(); ?>
	<?php the_content(); ?>
	<?php endwhile; endif; ?>

Example

	<?php $featured = new WP_Query('showposts=3&tag=featured'); ?>
	<?php if($featured->have_posts()) : ?>
	<ul id="featured">
	<?php while($featured->have_posts()) : $featured->the_post(); ?>
	<li><a href="" title="<?php the_title(); ?>"><?php the_post_thumbnail(‘full’); ?></a></li>
	<?php endwhile; ?>
	</ul>
	<?php endif; ?>

3. If Have Posts, While Have Posts, The Post

Shortcut: hp[tab]

This snippet of code is used all over WordPress template files. It is the beginning of The Loop (http://codex.wordpress.org/The_Loop), and is needed to fetch content from your WordPress database.

Code

	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Example

	<div class="content">
	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
	<h1><?php the_title(); ?></h1>
	<?php the_content(); ?>
	<?php endwhile; else: ?>
	<p>Sorry, no posts found.

<?php endif; ?> </div>

4. The Permalink

Shortcut: link[tab]

This snippet is used inside the loop to return an absolute URL to the item(s) your loop is processing – usually posts or pages. The link that is output on the page will vary depending on your permalink structure – but should your permalink structure change, you will not need to change this code.

Code

	<?php the_permalink(); ?>

Example

	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

5. Custom Field Value

Shortcut: cf[tab]

Custom fields add a huge amount of flexibility to a template. The limit really is either your imagination, or a self-defined line where you believe functionality is too in-depth for custom fields, and should instead be implemented through a plugin or custom post type.

Code

	<?php echo get_post_meta($post->ID, 'custom-field-key', true); ?>

One of my more recent uses for custom fields was on a client’s website that had a library of information about guitar effects pedals. The owner of said website affiliated with a few different online stores – and gets a commission if one of these effects pedals sells should a customer buy one after following a link from their website. The referral links worked so that my client could link directly to the product on one of the affiliate websites, and simply put some referrer information at the end of the URL.

I had set up a custom post type for the effects pedals, so using a custom field seemed like a simple step forward to achieve an easy way for the client to manage this data. The custom field key was “affiliate” and they added the link in the value box. On the template, the custom field was used to output a “Buy Now!” button.

Example

	<a class="button_buynow" href="<?php echo get_post_meta($post->ID, 'affiliate', true); ?>" title="Buy <?php the_title(); ?>">Buy Now!</a>

6. Custom Menu

Shortcut: menu[tab]

WordPress 3.0 introduced a fantastic new menu system, which moved us all away from using “wp_list_pages” and a bulky “exclude pages from lists” plugin. It’s a simple function call, but I use it at least once per website, so I turned it into a tab-triggered shortcut.

Code

	<?php wp_nav_menu( array( 'menu' => 'Navigation', 'sort_column' => 'menu_order' ) ); ?>

If you are building a theme to offer as a download, then you will likely use the theme_location parameter so that users can specify their own menu/multiple menus. My templates are usually built for clients, and by default I tend to name the menu “Navigation”, so in five key-strokes I have done all that is necessary to get the navigation onto the page. The rest is handled with CSS.


7. WordPress Include

Shortcut: wpinc[tab]

The syntax to include a file in WordPress is a bit different to the standard PHP include. I use WordPress includes in themes a lot when I’m working with custom post types and taxonomies. I like to have each post type and taxonomy in a separate file, for no reason other than to keep things clean and easy to read. However, doing it this way means the files have to be included in the theme’s functions.php file.

Code

	<?php include (TEMPLATEPATH . '/filename.php'); ?>

Example

	<?php include (TEMPLATEPATH . '/taxonomy_manufacturers.php'); ?>

8. Dynamic Sidebar

Shortcut: side[tab]

I can never exactly remember the code to display a dynamic sidebar, and even though I don’t use it that often, it’s a bit long to type out manually when I do.

Code

	<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?><?php endif; ?>

This of course relies on the other part of the code, which enables dynamic sidebars in the theme, being in the functions.php file

<?php
if (function_exists('register_sidebar') )
	register_sidebar(array(
	    'before_widget' => '<div class="widget">',
	    'after_widget' => '</div>',
	    'before_title' => '<h2>',
	    'after_title' => '</h2>',
	))
;
?>

9. Header & Footer Code

Shortcut: start[tab]

When ever I begin building a WordPress template, I put everything in the index.php file. I move everything to the separate header.php, footer.php and sidebar.php files once I’ve got the index.php how I want it – that’s just the way I like to work. All of my projects begin with the same code.

Code

	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	
	<head profile="http://gmpg.org/xfn/11">
	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
	
	<title><?php wp_title(''); ?></title>
	
	<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats -->
	
	<link rel="stylesheet" href="" type="text/css" media="screen" />
	<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_enqueue_script('jquery'); ?>
	<?php wp_head(); ?>
	
	</head>
	
	<body <?php body_class(); ?>>
	
	
	<?php wp_footer(); ?>
	</body>
	</html>

10. Get Header/Footer/Sidebar

Shortcut: gh[tab], gs[tab], gf[tab]

This is a three-in-one, but these code snippets are used in every WordPress template multiple times. Imagine how many seconds you could save not typing them out every time you used them! Yes, yes, you can copy and paste too – I know! See if you can guess which shortcut outputs which code…

Code

	<?php get_header(); ?>
	<?php get_footer(); ?>
	<?php get_sidebar(); ?>

Conclusion: Share Your Snippets!

As many of you are no doubt aware, the WordPress codex is very big. I think the key thing to try to maintain here is that only the most useful, longest and/or most used code snippets should be turned into tab-triggered shortcuts. Otherwise we simply go from trying to remember portions of code to trying to remember key-stroke sequences we have set up, which can be even more frustrating… plus, if you get caught on a computer other than your main workhorse, it can be tricky to remember the original code. The rule of thumb is that these should be time-savers, not crutches ;)

I hope you share any snippets that you do/would use in this manner in the comments!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.jeriko.de Jeriko

    Regarding the 7th snippet: WordPress provides a function get_template_part() to include files residing in the (parent) theme directory.

    • Brandon Jones

      Yup – I actually use that one all the time! Nice add Jeriko :)

      • http://www.blueprintstudio.org Dan Davies
        Author

        Oh, I was unaware of that. Great – thanks!

    • http://atinder.com atinder

      you can use even if files are not in parent directory

      as get_template_part(‘/includes/yourfile’)

    • http://www.andreapernici.com Andrea

      I agree with you ;) is better to reduce include and use wordpress native functions.

  • al

    css-tricks has a WP snippets area

    as well, check out the wp-snippets.com repository

    Al

    • al

      forgot another I reference all the time: snipplr.com, search on wordpress

    • http://varemenos.com/ Varemenos

      Thanks al! thats a really great share

  • http://www.intomylab.com Orange
  • http://www.Rarst.net Rarst

    1. blgoinfo() is fine (although there are a lot of function for that functionality, it depends), but example using it to point to jQuery is evil.

    2. Custom queries should reset data after themselves, wp_reset_query() or wp_reset_postdata() depending on what was done to global vars.

    7. As above – get_template_part() or related function should be used instead of simple include.

    8. dynamic_sidebar() is available since version 2.2 there is no point in checking for it in any modern code. Same with register_sidebar(). For some reasons sidebar-related stuff keeps being repeated with religious exists check. We don’t check for every new function since 2.2, why bother with these?

    9. Feed links were moved to be theme feature in 3.0 (or something like that, hadn’t dealt with themes lately). jQuery is better specified as dependency and/or queue in wp_enqueue_script(), unless you really need it on every single page.

    • http://www.Rarst.net Rarst

      Typo In 9, meant wp_enqueue_scripts() function and hook of same name, not wp_enqueue_script() that does actual queueing.

    • Spencer

      It should be noted that get_template_part should be used to load actual template files, not things like extra functions/functionality.

      See: http://justintadlock.com/archives/2010/11/17/how-to-load-files-within-wordpress-themes

      • Brandon Jones

        Yup – that happens to be a fantastic article reference btw :)

      • http://www.Rarst.net Rarst

        It’s a little more complex than functionality/template distinction.

        Really it depends on two things: if you want file loaded to be overridable by child theme and if you want global variables to work properly in it. WP functions are mostly there to ensure these two points.

    • http://czent.com/ Deb

      Yey for point 8! We don’t need to keep checking if exists for dynamic sidebar function, its been there for ages.

      And yes since WP3 we need add_theme_support(‘automatic-feed-links’); for feed urls to work properly, so optional theme feature now.

      I tell you man it was such a painful thing to find out that the custom theme needed ‘feed support’ after much head scratching why feed url won’t show up posts, instead it would show comments feed, wth!?

    • Keith

      Rarst, why is #1 evil and what should be the proper way?

      • http://www.Rarst.net Rarst

        Script should be registered and enqueued through wp_register_script() / wp_enqueue_script() and appropriate hooks. There is nothign wrong with bloginfo used for building URL, just that building url to script file and including it with script tag in theme’s body is bad practice.

    • http://curtismchale.ca curtismchale

      Dang, I made the same list at midnight and figured I’d comment in the morning. Certainly haven’t seen the quality I’d like in the stuff here yet. A number of the items pointed out have been best practice for a while and shouldn’t have shown up at all.

  • http://thewebprincess.com The Web Princess

    I want to +1 this… but there’s no means to do so!

  • http://abdullah.webdesignerart.com Abdullah

    WAon Nice article, Its organize my work more….

  • http://www.ree-she.com Rishi Luchun

    Thanks for these, been looking for a post like this!

  • http://wplava.com Ahmad

    i wish you can add variation for ” If Have Posts, While Have Posts, The Post”like grid display of the topics

    regards

  • http://www.vareen.co.cc Neerav

    A cool free tool for Windows called ‘Texter’ from ‘lifehackers’, I use that one for this very purpose.

    http://goo.gl/YZOR

    Although not updated since 2007, its worth try at least.

  • http://insightorange.com/salman Salman

    getting list of categories and ability to change the rendering markup with walker_category calss

    copy this any where in tempalte you want
    wp_list_categories( array(‘orderby’ =>’order’,'exclude’ => ’1,10′,’title_li’ => ”,’style’=>none,’walker’ => new walker_custom_class.php()));
    read more about wp_list_categories attributes wordpress codex

    next all you have to do it to create a new class extending from Walker_Category in our case it will be called ‘walker_custom_class’ and copy ‘start_el’ function from wp-includes/category-template.php file line number 830
    and change that how ever you want and create crazy category listing

    same concept can be used for creating menus and pages

    enjoy and thanks for sharing these snippets

  • http://inteoria.net Alessandro Muraro

    wow great post, it pushed me to start building my own snippets collection…

    thx a lot!

  • http://universowp.com.br Marlon

    Nice tips! I like the example about Custom fields.

    I would add that I agree with the notes of Rarst.

    And I love this cheat sheets (some may be slightly out of date):

    http://amilha.com/arquivos/Advanced-WordPress-Help-Sheet.pdf
    http://amilha.com/arquivos/Wordpress-Cheat-Sheet.pdf
    http://amilha.com/arquivos/WordPress-Help-Sheet_pt_BR.pdf

    :)

  • http://socialmedia101.artizondigital.com Sue Surdam

    Thanks for sharing your fav snippets and shortcut keys. The article is a great reference for anyone who is writing or customizing themes. I’ll be setting up my shortcuts today!

  • http://pointandstare.com Lee

    As above – 7 is incorrect.
    Also the last one – ‘Start – doctype’ – This depends on your where/ what you’re targeting.

  • http://insightorange.com/salman Salman

    parse shortcode any where in the template files

    $wp_embed = new WP_Embed();
    $post_embed = $wp_embed->run_shortcode(‘[embed]your-video-url[/embed]‘);

    or use custom custom field to run the shortcode

    $wp_embed = new WP_Embed();
    $post_embed = $wp_embed->run_shortcode(get_post_meta($post->ID, ‘youtube’, true));

    originally shared by Danny Carmical (http://www.luckykind.com/)

    hope this helps

  • arnold

    please make an article about best practices in working with wordpress ? , you know something that involves coding…and are there any screencast coming ?
    thanks

  • Connor Crosby

    This is a great idea! I normally just copy and paste the snippets from eBooks or online. Thanks :)

  • http://tutspress.com TutsPress

    Very good resource. Thanks :)

  • http://reloadweb.co.uk Mohsin

    Nice article, I’m gonna have to find a plugin for Notepad++ that does the same thing. By the way I like what Rarst has to suggest.

    • Brandon Jones

      You can also just pick up TextExpander or ActiveWords and they’ll do the same thing for you… everywhere (not just inside a coding app) :)

      • http://www.giulianoliker.com Giuliano

        PhraseExpress is also nice tool.

  • http://christophedebruel.be Christophe Debruel

    Nice list :D and very usefull links in the comments as well. But is there a snippet list for text expander?

  • http://lukemcdonald.com Luke

    For #1, consider using get_template_directory_uri() instead (for the parent template directory) or get_stylesheet_directory_uri() (for the child template directory).

    http://codex.wordpress.org/Function_Reference/get_bloginfo#Parameters

  • http://www.wearepixel8.com Erik Ford

    Nice list for those just getting their feet wet theming for WordPress. You first snippet blog_info( 'template_directory' ); is no longer recommended. You should use get_template_directory_uri(); or get_stylesheet_directory_uri();, in cases of child theming.

    Your example would look like this:


    <img src="/images/header.jpg" alt="Header" />

    • Brandon Jones

      Yep – OR – set the theme directory as a global variable that you can use on the fly ;)


      if(!defined('WP_THEME_URL')) {
      define( 'WP_THEME_URL', get_template_directory_uri());
      }

  • http://www.librodeapuntes.es Bruno Rico

    1.-Enqueue a stylesheet:

    wp_enqueue_style( ‘cssname’, get_template_directory_uri() . ‘/style.css’);

    2.-Enqueue a js:

    wp_enqueue_script( ‘js-name’, get_template_directory_uri() . ‘/js/name.js’, array( ‘jquery’ ), ’2011-04-28′ );

    3.-Display post thumbanils on a list:

    echo ‘ &ltli> &lta href=”‘.get_permalink().’” title=”‘.get_the_title().’.”>’;
    echo the_post_thumbnail(‘thumbnail’, array(‘class’ => ‘thumbnail’));
    echo ‘ &ltspan class=”photofooter”>’.get_the_title(). ‘ &lt/span> &lt/a> &lt/li>’;

    • Brandon Jones

      Nice Bruno!

  • http://antoinedescamps.fr Antoine Descamps

    The include syntax mentionned in this article is the normal PHP syntax, nothing related with WordPress.
    If you want to use include the WordPress way it’s “get_template_part”.

  • http://www.georgewiscombe.com George Wiscombe

    I find myself using post formats more and more so recently added this to my arsenal…

    <div class="”>

    Brilliant post.

    Thanks,
    George

  • http://contempographicdesign.com Chris Robinson

    Pretty simple but handy if statement, wrote this up for my theme framework to check if a post has more than one image attached. In my case I used it to check if the post has more than one image display a slider, else display the single image.

    <?php
    $attachments = get_children(
    array(
    ‘post_type’ => ‘attachment’,
    ‘post_mime_type’ => ‘image’,
    ‘post_parent’ => $post->ID
    ));
    if(count($attachments) > 1) { ?>
    <!– Do something like show a slider –>
    <?php } else { ?>
    <!– Display a single image –>
    <?php } ?>

    • Brandon Jones

      That’s nice Chris! I have something similar that extends this idea to check for timthumb.php (for resizing) and whether or not the user wants to launch the gallery into a lightbox on click… so many great little snippets out the surrounding images… which is pretty impressive for the community when you consider how limited the generic Gallery API is (IMO).

  • http://www.clintoncherry.com Clinton

    I thought WP was the universal acronym for Windows Phone…

    • http://www.ruturaaj.com/ Ruturaaj

      :-) … now don’t tell me Microsoft is planning to buy WordPress. ;-)

  • Pingback: 10 Wordpress snippeta koje svaki developer treba memorirati u telefon | WordPress škola

  • Pingback: 10 Wordpress Code Snippets every WP dev need to have on tap | Essential Wordpress

  • http://simplease.at Andreas Riedmüller

    Thanks for sharing! In your Header and Footer snippet you can replace the doctype with: “” than its shorter and it does the same :)

    Here are some clips that I use regularly:

    To start something I use the “The World’s Best HTML Template” from Jens Meiert (http://meiert.com/en/blog/20080429/best-html-template/) with the shortcut: html
    And I love it!


    Title

    Content

    To query posts this is what I use, i like it more because for me its easier to read.
    post_content);
    echo $post->post_title;
    echo $post->post_content;
    }
    ?>

    And extremely helpful if you work with the attachments Plugin:

    0 ) : ?>
    <?php for ($i=0; $i

  • http://simplease.at Andreas Riedmüller

    Thanks for sharing! In your Header and Footer snippet you can replace the doctype with: than its shorter and it does the same
    Here are some clips that I use regularly:

    To start something I use the “The World’s Best HTML Template” from Jens Meiert (http://meiert.com/en/blog/20080429/best-html-template/) with the shortcut: html
    And I love it!


    Title

    Content

    To query posts this is what I use, i like it more because for me its easier to read.

    post_content);
    echo $post->post_title;
    echo $post->post_content;
    }
    ?>

    And extremely helpful if you work with the attachments Plugin:

    0 ) : ?>
    <?php for ($i=0; $i

  • http://www.xpertdeveloper.com Avi

    get_option() is the good functions to get the all the wordpress options like:


    echo get_option('home');

    http://codex.wordpress.org/Function_Reference/get_option

  • Pingback: [30/07] Revue de presse | Les conférences du Sud

  • raff

    in custom query don’t forget
    wp_reset_postdata()

  • http://www.mk-dizajn.com/ mart

    Hi,

    About # 6…

    I did have to return to wp_list_pages …

    When I develop site with multilanguage plugin qtranslate it adds some code to post name and ti looks like this:

    http://goo.gl/pMf44

    it is ugly …

    And one more thing..

    The menu tab is under appearance tab so I have to elevate higher role for user to handle the contents … but I dont like that

  • EmpreJorge

    I use Texter in Windows 7 and Windows Vista for my snippets :D

    • Brandon Jones

      Nice share Jorge!

  • http://etuts.org Sudheer Ranga

    Thanks for this post. My fist code snippets is to have a basic html as i work on notepad. I use a plugin on notepad++ that works like text expander and i am loving it. It helps me code faster.

  • Pingback: Denise

  • http://www.wpexplorer.com AJ

    Great stuff. I’m going to add all these to my super awesome snippet bin :)

  • Pingback: Best of Tuts+ in July - Game Lot

  • Pingback: 10 сниппетов, которые должен знать каждый разработчик wordpress | webkladez - Полезные уроки для photoshop, wordpress, joomla

  • Pingback: 10 WordPress Code Snippets Theme Developers Should Have on Speed Dial

  • Pingback: 12 WordPress Code snippets for theme developers |

  • http://www.rezb.com/ Sasha

    For all you who are using Notepad++ and FingerText plugin you can download snippets file here: http://www.rezb.com/12-wordpress-code-snippets-for-theme-developers/ They are all based on this article, only prefixed with “wp” for convenience…

    p.s. I’m not sure if it is ok to publish links to other blogs in comments so forgive me if I’m breaking some of the rules…

  • Weerayut Teja

    Great Idea, It make my work fluently. Thank you Dan.
    ah I use “LifeHacker Texter” to manipulate and insert my custom code snippet.

  • Pingback: Miscalanious links need sorting « Blogging with Phil

  • Pingback: 10 WordPress Code Snippets Theme Developers Should Have on Speed Dial | Wptuts+ | LPH Design

  • Pingback: Tweet-Parade (no.31 Jul-Aug 2011) | gonzoblog.nl

  • http://www.ruturaaj.com/ Ruturaaj

    I see many of your code snippets are actually WordPress functions. It’s better to use a code editor that allows you to reference to external library. If your code editor allows you, just download the latest WordPress package and add “wp_admin” and “wp_includes” to your external reference. This will add all WordPress functions to your Code Editor’s so-called Intellisense list (the list that lists all the functions). I don’t want to advertise any specific editor here, but would like to mention “Netbeans for PHP” out of the love for Netbeans. :-) You will notice that just type “wp_” and press CTRL + Space (sorry, Mac people… I don’t know what’s equivalent on your systems) and you will get the complete list of commands. This way, you don’t need to add “wp_head” and “wp_footer” to your Code Snippets.

    If you’re a serious WordPress programmer, you better switch to a complete IDE (Integrated Development Environment) like Netbeans for PHP. But if you’re a Student, learning WordPress programming, I’d recommend you to keep yourself away from such shortcut methods. All these time savers are best in professional life when we’re always asked to do more in less time. Yeah, I may sound like an old fashioned school teacher here… but trust me, more you write the code by hand, more you learn the syntax and better you become to debug the code quickly. At least this is my personal experience and I love to be completely on my own at the time of debugging code and solving errors; thanks to my old days pure hand-typing of code.

    • http://www.ruturaaj.com/ Ruturaaj

      Ok, here is my small contribution to your initiative:

      ## WordPress Plugin’s default header…

      /*
      Plugin Name:
      Plugin URI:
      Description:
      Version: 1.0
      Author: Ruturaaj
      Author URI:
      Author Email:
      License:
      Copyright 2012 TODO (email@domain.com)
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License, version 2, as
      published by the Free Software Foundation.
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      GNU General Public License for more details.
      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      */

      Just fill-in your default values and best to leave only Plugin Name, URI and Description empty.

      ==============================================================================

      ## WordPress Theme File Header

      /*
      Theme Name:
      Theme URI:
      Description: Professional WordPress Theme developed by Ruturaaj.
      Version: 1.10
      Author: Ruturaaj.
      Author URI:
      Author Email:
      License:

      Copyright 2012 TODO (email@domain.com)
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License, version 2, as
      published by the Free Software Foundation.
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      GNU General Public License for more details.
      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      */

  • http://twitter.com/nine_L Lenin

    How about get_template_directory_uri() instead of bloginfo('template_directory')

  • Giancarlo Leonio

    Thank you for this post on WordPress code snippets for theme developers. I found it very useful. I made a board on Verious.com with this and other top resources for those interested in extending the capabilities of their WordPress Site. http://www.verious.com/board/Giancarlo-Leonio/code-snippets-to-get-started-with-wordpress