WordPress Cheat Sheet

Basic Template Files

File NameDescription
style.cssstyle sheet file
index.phphome page file
header.phpheader content file
single.phpsingle post page file
archive.phparchive/category file
searchform.phpsearch form file
search.phpsearch content file
404.phperror page file
comments.phpcomments template file
footer.phpfooter content file
sidebar.phpsidebar content file
page.phpsingle page file
front-page.phplatest posts or static page
tag.phpdisplay tags in archive format
category.phpdisplay categories in archive format

Header Functions

FunctionDescription
<?php site_url(); ?>root url for website
<?php wp_title(); ?>title of specific post/page
<?php bloginfo('name'); ?>title of site
<?php bloginfo('description'); ?>site description
<?php get_stylesheet_directory(); ?>stylesheet folder location
<?php bloginfo('stylesheet_url'); ?>style.css file location
<?php bloginfo('pingback_url'); ?>pingback url
<?php bloginfo('template_url'); ?>template folder path
<?php bloginfo('version'); ?>wordpress blog version
<?php bloginfo('atom_url'); ?>atom url
<?php bloginfo('rss2_url'); ?>rss2 url
<?php bloginfo('url'); ?>root url for website
<?php bloginfo('html_type'); ?>html version
<?php bloginfo('charset'); ?>charset parameter

Navigation Menu

// Default Navigation Menu	
<?php wp_nav_menu(); ?>	

// Specific Navigation Menu	
<?php wp_nav_menu( array('menu' => 'Project Nav' )); ?>	

// Category Based Navigation	
<ul id="menu">	
    <li <?php if(is_home()) { ?> class="current-cat" <?php } ?>>	
        <a href="<?php bloginfo('home'); ?>">Home</a>
    </li>	
    <?php wp_list_categories('title_li=&orderby=id');?>	
</ul>	

//Page Based Navigation	
<ul id="menu">	
    <li <?php if(is_home()) { ?> class="current-page-item" <?php } ?>>	
        <a href="<?php bloginfo('home'); ?>">Home</a>
    </li>	
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li=');?>	
</ul>

Template Functions

FunctionDescription
<?php the_content(); ?>content of posts/pages
<?php if(have_posts()): ?>check if there are posts
<?php while(have_posts()): the_post(); ?>shows posts
<?php endwhile; ?>closes loop
<?php endif; ?>closes if
<?php get_header(); ?>header.php file contents
<?php get_sidebar(); ?>sidebar.php file contents
<?php get_footer(); ?>footer.php file contents
<?php the_time('m-d-y'); ?>the date is ’08-18-07′
<?php comments_popup_link(); ?>link to comments of post
<?php the_title(); ?>title of post/page
<?php the_permalink(); ?>url of post/page
<?php the_category(); ?>category of post/page
<?php the_author(); ?>author of post/page
<?php the_ID(); ?>id of post/page
<?php edit_post_link(); ?>edit link of post/page
<?php wp_list_bookmarks(); ?>links from blogroll
<?php comments_template(); ?>comment.php file contents
<?php wp_list_pages(); ?>list all pages
<?php wp_list_categories(); ?>list all categories
<?php next_post_link('%link'); ?>url to next post
<?php previous_post_list('%link'); ?>url to previous post
<?php get_calendar(); ?>show post calendar
<?php wp_get_archives(); ?>list of archive urls
<?php posts_nav_link(); ?>next and previous post link
<?php rewind_posts(); ?>rewinds post for a second loop

The Loop

//Basic Loop	
<?php if(have_posts()) { ?>	
    <?php while(have_posts()) { ?>	
        <?php the_post(); ?>	
            <?php // custom post content code for title, excerpt and featured image ?>	
    <?php } // end while ?>	
<?php } // end if ?>

Extra Functions

FunctionDescription
/%postname%/custom permalinks
<?php include(TEMPLATEPATH . '/x'); ?>include file from template folder
<?php the_search_query(); ?>value returned from search from
<?php _e('Message'); ?>return translated text from translate()
<?php wp_register(); ?>register link
<?php wp_loginout(); ?>login/logout link
<!--nextpage-->divide content into pages
<!--more-->cut off content and create link to full post
<?php wp_meta(); ?>admin meta data
<?php timer_start(); ?>start page timer (header.php)
<?php timer_stop(1); ?>time to load the page (footer.php)
<?php echo get_num_queries(); ?>show queries executed to generate page

Template Bloginfo Tags

There’s another category of templates tags that we’ll simply call bloginfo tags. They play one role, which is to fetch information about your WordPress site from the database. This is mainly the information you feed to your WordPress site in your admin area via the User Profile and Settings -> General. Once the information is retrieved from your databases, these tags will then display the same on your site as you place them.

You can slightly modify the structure of bloginfo, so that instead of just displaying the information retrieved, you can use it (the info) elsewhere in your PHP code. How convenient? More about that in a moment. Here are the most common bloginfo tags:

  • <?php bloginfo(‘name’); ?> – This displays the title of your WordPress blog/site
  • <?php bloginfo(‘url’); ?> – This template tag displays the URL of your blog
  • <?php bloginfo(‘description’); ?> – This displays the description, or rather the tagline, of your blog.
  • <?php bloginfo(‘charset’); ?> – Displays the character set used to encode your site. Default is UTF-8
  • <?php bloginfo(‘stylesheet_url’); ?> – This shows URL to the CSS stylesheet of your active theme
  • <?php bloginfo(‘version’); ?> – Displays the WordPress version you’re using
  • <?php bloginfo(‘language’); ?> – Displays the language of WordPress
  • <?php bloginfo(‘rss_url’); ?> – Displays URL for the RSS 0.92 feed
  • <?php bloginfo(‘rss2_url’); ?> – Displays URL for the RSS 2.0 feed

There are several other bloginfo tags you can use to enhance your WordPress theme. Now about that little bloginfo modification we talked about a couple of seconds ago. So far, we’ve been using <?php bloginfo(); ?>. Let’s modify this to: <?php $bloginfo = get_bloginfo ($show, $filter); ?>. Allow me to break down the parameters:

  • $show   This is the keyword you use to name the information you want to retrieve from the database. Examples include ‘name’, ‘url’, ‘description’, ‘admin_email’ etc
  • $filter – This just allows you to filter the information retrieved. By default, it’s set to ‘raw’, which just means the value of $show is returned as is. Setting this to ‘display’ will cause the value of $show to be passed through the wptexturize() function first. Don’t sweat about this at the moment though.


VISUALIZE THE WORDPRESS TEMPLATE HIERARCHY
Template Hierarchy | Theme Developer Handbook | WordPress Developer Resources
WordPress Developer Super Cheat Sheet
WordPress theme - The Anatomy, an Infographic - Yoast
WordPress V5.0+ Template Tag Reference Guide as of Version 5.2
Screenshot of www.wpbeginner.com

Default WordPress CSS Cheat Sheet

.rtl {}
.home {}
.blog {}
.archive {}
.date {}
.search {}
.paged {}
.attachment {}
.error404 {}
.single postid-(id) {}
.attachmentid-(id) {}
.attachment-(mime-type) {}
.author {}
.author-(user_nicename) {}
.category {}
.category-(slug) {}
.tag {}
.tag-(slug) {}
.page-parent {}
.page-child parent-pageid-(id) {}
.page-template page-template-(template file name) {}
.search-results {}
.search-no-results {}
.logged-in {}
.paged-(page number) {}
.single-paged-(page number) {}
.page-paged-(page number) {}
.category-paged-(page number) {}
.tag-paged-(page number) {}
.date-paged-(page number) {}
.author-paged-(page number) {}
.search-paged-(page number) {}
Screenshot of www.wpbeginner.com