WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Themes» WordPress Theme Cheat Sheet for Beginners

WordPress Theme Cheat Sheet for Beginners

Last updated on March 27th, 2018 by Editorial Staff
88 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
WordPress Theme Cheat Sheet for Beginners

Are you looking for a WordPress theme cheat sheet to quickly modify your theme or create a new custom theme? WordPress comes with many built-in template tags that you can use to get a head start. In this article, we will share a WordPress theme cheat sheet for beginners.

WordPress theme development cheat sheet for beginners

Before Getting Started

WordPress comes with a powerful templating engine that allows theme developers to create beautiful designs for WordPress powered websites. There are both premium and free WordPress themes that you can install on your website.

Each WordPress theme comes with a number of customization options. These options allow you to change colors, add header images, setup navigation menus, and more.

However, you are still limited to what features your theme supports. Sometimes you may want to make slight changes to your WordPress theme that require some coding. To do that, you will need to know some basic PHP, HTML, and CSS.

First thing you would want to do is to familiarize yourself with how WordPress works behind the scenes and WordPress theme templates.

After that there are some best practices you may want to follow. For example, creating a child theme instead of making your changes directly into your theme files.

You can also practice on your theme by installing WordPress on your computer.

That being said, let’s dive into our WordPress theme cheat sheet for beginners.

Basic WordPress Theme Templates

Basic WordPress theme files

Each WordPress theme is made up of different files called templates. All WordPress theme must have a stylesheet and an index file, but usually they come up with a lot of other files.

Below is the list of basic files that every theme has:

  • style.css
  • header.php
  • index.php
  • sidebar.php
  • footer.php
  • single.php
  • page.php
  • comments.php
  • 404.php
  • functions.php
  • archive.php
  • searchform.php
  • search.php

If you are building your own theme, then you can start with one of the WordPress starter themes. These themes come with ready to use WordPress template files and CSS that gives you a framework to build upon.

Template Tags in Header

WordPress comes with a lot of handy functions that can be used to output different things throughout your theme. These functions are called template tags.

First and probably the most important function that is required in all standard compliant WordPress themes is called wp_head, and it looks like this:

<?php wp_head(); ?>

This code fetches all the important HTML WordPress needs to add in the <head> section of every page on your website. It is also essential for many WordPress plugins to work properly on your website.

Following is a list of template tags that you will commonly find and use in your theme’s header.php file. However, they can also be used elsewhere on your theme when you need them.

// Title of the Blog, or Blog Name
<?php bloginfo('name'); ?> 

// Title of a Specific Page
<?php wp_title(); ?>

// Exact URL for the site
<?php bloginfo('url'); ?> 

// Site's Description
<?php bloginfo('description'); ?> 

// Location of Site’s Theme File
<?php bloginfo('template_url'); ?>

// Link to the Style.css location
<?php bloginfo('stylesheet_url'); ?>  

// RSS Feed URL for the site
<?php bloginfo('rss2_url'); ?> 

// Pingback URL for the site
<?php bloginfo('pingback_url'); ?>

// WordPress version number 
<?php bloginfo('version'); ?> 

Template Tags Used in Other Theme Files

Now let’s take a look at some other commonly used template tags and what they do.

Template tags that include other templates

Following template tags are used to call and include other templates. For example, your theme’s index.php file will use them to include header, footer, content, comments, and sidebar templates.

//Displays Header.php file content
<?php get_header(); ?> 

// Displays Footer.php file content
<?php get_footer(); ?>

// Displays Sidebar.php file content
<?php get_sidebar(); ?>

// Displays Comment.php file content
<?php comments_template(); ?> 

Following template tags are used inside the WordPress loop to display content, excerpt, and meta data from your posts.

// Displays the Content of the Post
<?php the_content(); ?>  

// Displays the excerpt that is used in Posts
<?php the_excerpt(); ?>

// Title of the Specific Post
<?php the_title(); ?>

// Link of the Specific Post
<?php the_permalink() ?>

// Category of a Specific Post
<?php the_category(', ') ?>

// Author of the Specific Post
<?php the_author(); ?> 

//ID of a Specific Post
<?php the_ID(); ?>

// Edit link for a Post 
// Oonly visible to logged in users with editing privileges
<?php edit_post_link(); ?>

// URL of the next page
<?php next_post_link(' %link ') ?>

// URL of the previous page
<?php previous_post_link('%link') ?> 

WordPress themes come with widget-ready areas called Sidebars. These are locations in your theme files where users can drag and drop WordPress widgets. Often a theme has multiple locations where users can add widgets.

However, most commonly these widget areas are located in the right or left sidebar of the theme layout. To learn more, see our guide on how to add dynamic widget ready sidebars in your WordPress theme.

Here is the code used to display a sidebar in your theme.

<?php 
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
	return;
}
?>

<aside id="secondary" class="widget-area" role="complementary">
	<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->

You will need to replace sidebar-1 with the name defined by your theme for that particular widget-ready area or the sidebar.

Template Tags to Display Navigation Menus

WordPress comes with a powerful menu management system that allows users to create navigation menus for their website. A WordPress theme can have more than one navigation menu location.

See our guide on how to create your own custom navigation menus in a WordPress theme.

Following is the code that will be used in your theme to display a navigation menu.

<?php
wp_nav_menu( array( 
    'theme_location' => 'my-custom-menu', 
    'container_class' => 'custom-menu-class' ) ); 
?>

Theme location depends on the name your theme used to register the navigation menu. The CSS container class can be called anything that you like. It will surround your navigation menu, so that you can style it accordingly.

Miscellaneous Template Tags

Following are some of the tags that you’ll commonly use throughout your WordPress theme.


// Displays the date current post was written
<?php echo get_the_date(); ?> 

// Displays the last time a post was modified
get_the_modified_time

// Displays the last modified time for a post
<?php echo the_modified_time('F d, Y'); ?>

// Displays post thumbnail or featured image
<?php the_post_thumbnail( ); ?>

// Displays monthly archives
<?php wp_get_archives( ); ?>

// Displays the list of categories
<?php wp_list_categories(); ?>

// Displays the gravatar of a user from email address
// 32 pixels is the size, you can change that if you need
<?php echo get_avatar( 'email@example.com', 32 ); ?>

// Displays gravatar of the current post's author
<?php echo get_avatar( get_the_author_meta( 'ID' ), 32 ); ?>

Conditional Tags in WordPress Themes

Conditional tags are functions that return results in True or False. These conditional tags can be used throughout your theme or plugin to see if certain conditions are met and then do something accordingly.

For example, if the current post has a featured image or not. If it doesn’t have a featured image, then you can show a default featured image instead.

<?php
if ( has_post_thumbnail() ) {
    the_post_thumbnail();
}
else {
    echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) 
        . '/images/thumbnail-default.jpg" />';
}
?>

Following are a few more conditional tags that you can use.

// Checks if a single post is being displayed
is_single() 

// Checks if a page is being displayed
is_page() 

// Checks if the main blog page is displayed
is_home() 

// Checks if a static front page is displayed
is_front_page() 

// Checks if current viewer is logged in
is_user_logged_in() 

There are many more conditional tags that you can use. The full list of conditional tags can be found in the WordPress codex page about conditional tags.

The WordPress Loop

The Loop or the WordPress loop is the code used to fetch and display posts in WordPress. Many WordPress template tags may only work inside the loop as they are associated with the post or post_type objects.

Following is an example of a simple WordPress loop.

<?php
 
// checks if there are any posts that match the query
if (have_posts()) :
 
  // If there are posts matching the query then start the loop
  while ( have_posts() ) : the_post();
 
    // the code between the while loop will be repeated for each post
    ?>
 
    <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
 
    <p class="date-author">Posted: <?php the_date(); ?> by <?php the_author(); ?></p>
 
    <?php the_content(); ?>
 
    <p class="postmetadata">Filed in: <?php the_category(); ?> | Tagged: <?php the_tags(); ?> | <a href="<?php comments_link(); ?>" title="Leave a comment">Comments</a></p>
 
    <?php
 
    // Stop the loop when all posts are displayed
 endwhile;
 
// If no posts were found
else :
?>
<p>Sorry no posts matched your criteria.</p>
<?php
endif;
?>

To learn more about the loop check out What is a Loop in WordPress (Infographic).

We hope this article helps you as the basic WordPress theme cheat sheet for beginners. You may also want to see our list of the most useful tricks for the WordPress functions file.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

88 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Fix the Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

30 Comments

Leave a Reply
  1. Henry Obilor says:
    Feb 8, 2019 at 4:03 am

    I would love to ask when creating a new theme. Can I create my own header.php and use a premium theme footer.php?

    Mixing yours with already built template. Will it work?

    Reply
    • WPBeginner Support says:
      Feb 8, 2019 at 11:30 am

      That would heavily depend on the content of the footer.php and how you have your theme coded. If you have the footer then the best method would be to test on a local installation.

      Reply
  2. Biplob says:
    Apr 25, 2016 at 9:41 am

    It’s awesome thing. it’s very useful

    Reply
  3. Zaki says:
    Jan 27, 2016 at 4:57 pm

    This is certainly not for beginners. I am afraid I will end up with messing up my website. Coding part is completely unclear. I would appreciate if you can some great screenshots to illustrate “How to add a custom page”.

    Reply
  4. Sanam says:
    Aug 23, 2015 at 2:12 am

    Bro where to paste that code in functions.php

    Reply
    • WPBeginner Support says:
      Aug 23, 2015 at 3:45 pm

      At the bottom. If you have ?> tag as the last line then you need to paste code before that line.

      Reply
  5. Shahbaz Ahmed Bhatti says:
    Feb 8, 2014 at 4:42 am

    Very Nice and Goooood Work Keep it up, Very goood information for Basic

    Reply
  6. Solomon says:
    Nov 28, 2013 at 10:34 am

    Thanks very much, i really appreciate.

    Reply
  7. Pali Madra says:
    Jun 15, 2012 at 8:41 am

    Thanks for the great tutorial. I recommend the tutorial to anyone trying to learn WordPress.

    Keep up the good work!

    Reply
  8. Ben says:
    Jun 14, 2012 at 12:10 am

    Thanks for a very helpful article. Just want I have been looking for.

    Thanks.

    Ben

    Reply
  9. madalinignisca says:
    Nov 17, 2011 at 2:29 am

    what is – Site’s Description

    I think it is

    Reply
  10. madalinignisca says:
    Nov 17, 2011 at 2:28 am

    what is “<?php bloginfo(%u2019description%u2019); ?> – Site’s Description” ? I think it is “<?php bloginfo(‘description’); ?>”

    Reply
  11. mirzayasir4 says:
    Aug 28, 2011 at 5:03 pm

    That’s great useful cheet sheet when you are doing editing in themes. Thanks

    Reply
  12. John says:
    May 31, 2010 at 2:54 am

    Fantastic, I’ve been looking for an easy WordPress cheatsheet for a while, thanks for doing this, makes life a lot easier and I can get a bit more creative. WordPress has such a lot of power under the hood.

    Reply
  13. mark says:
    Mar 24, 2010 at 8:32 am

    this is gr8 for beginner

    Reply
  14. Russell Poulter says:
    Feb 25, 2010 at 4:51 am

    This is SO bookmarked!

    Thanks.

    Reply
  15. asif eminov says:
    Feb 2, 2010 at 12:14 pm

    Thanks this details.

    Reply
  16. Ersatzknochen says:
    Dec 27, 2009 at 2:54 pm

    Yeah, very useful. Thank you.

    Reply
  17. Delighted says:
    Oct 24, 2009 at 4:22 am

    Thank you for the Codes in Header.php part, Very easy to understand and VERY useful! thank you for this.

    Reply
  18. SleepY says:
    Oct 24, 2009 at 4:07 am

    Wow….thats what i was looking for since days.

    thanks a lot !

    Reply
  19. Victor Duwon Jackson says:
    Oct 23, 2009 at 12:39 pm

    This is great, Thanks.

    Reply
  20. Manoj says:
    Oct 12, 2009 at 8:15 am

    Great info! bookmarked :)

    Reply
  21. Obed Ward says:
    Sep 15, 2009 at 1:01 pm

    Excellent WP theme cheat sheet, going to bookmark it (and of course tweet it). Thanks!

    Reply
  22. Naeem Noor says:
    Sep 14, 2009 at 6:09 pm

    Very Useful, just printed it.

    Reply
  23. Blog2Life says:
    Sep 8, 2009 at 8:48 pm

    These shortcodes are just what I was looking for to start work on some new themes.. thanks for the post and keep up the good work!

    Reply
    • Hami says:
      Sep 10, 2009 at 3:13 pm

      Yes exactly. This post has solved out and let us (beginners) start working instantly on new ideas :D

      Reply
  24. A.D.K. says:
    Aug 11, 2009 at 12:29 pm

    This is very useful thanks.

    Reply
  25. Jon Rawlins says:
    Jul 15, 2009 at 5:18 am

    Retweeted this for you. Just about to get a blog setup for myself, so this site has been very useful.

    Reply
  26. Angad Sodhi says:
    Jul 14, 2009 at 4:34 pm

    Aah! Bookmarking this right away..
    Referring the default theme for these small details is now history!
    Thank you people.

    Reply
  27. DaveK says:
    Jul 14, 2009 at 11:49 am

    Cool, Thanks for sharing, consider it tweeted ;-)

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
OptinMonster
OptinMonster
Convert website visitors into email subscribers. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
LiveChat logo
LiveChat Inc Coupon
Get a 30 day free trial and 30% OFF LiveChat, one of the best live chat service providers for WordPress users.
ConvertKit Coupon Code
ConvertKit Coupon
Get a 14-day no risk FREE trial with this powerful email marketing software.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.