Quick Reference Cheat Sheet for WordPress Scalability Best Practices

WordPress Cheat sheet for scaling a WordPress website


Are you a WordPress developer? Or do you aim to be one? Isn’t it a hassle doing repetitive tasks again and again to keep your WordPress website going?

Well, you can avoid wasting your precious time by simply using the CMS to its 100% potential. Coding can get really tough at times when creating a WordPress website. That is why it is utterly necessary to master WordPress tags and their functions.

WordPress possesses numerous built-in template tags that we can use to work even more efficiently. These cheat codes let you get started with your WordPress website projects without any delay.

Basic Theme Template Files

You can find a number of files that are also known as templates in every WordPress theme. All of them come with a stylesheet and an index file as well as many other files. We made it easier for you to find the certain ones that will take you directly to your required file.

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

Cheat Sheet For Header

  • ˂?pfp wp_head(); ?˃

Template tags are used to output various things all over the WordPress theme. The most necessary function that sets the standard in the themes is known as wp_head. We see it like this:

You get to fetch any important HTML that is required and add in the ˂head˃ part of the pages on your WordPress website. We have prepared a list of template tags for you to use in the theme’s header.php file.

Blog Name/ Title of the Blog˂?pfp bloginfo( ‘name’ ); ?˃
Title of any Certain Page˂?php wp_title( ); ?˃
Exact URL for Website˂?php bloginfo( ‘url’ ); ?˃
Site Description<?php bloginfo(‘description’); ?>
Location of Theme File<?php bloginfo(‘template_url’); ?>
Link to the Style.css<?php bloginfo(‘stylesheet_url’); ?>
RSS Feed URL for website<?php bloginfo(‘rss2_url’); ?>
Pingback URL for site<?php bloginfo(‘pingback_url’); ?>
WordPress version number<?php bloginfo(‘version’); ?>

WordPress Cheat Sheet For The index.php File

See the list of tags that will help you include header, footer, content, comments, and sidebar patterns.

Shows Header.php file content<?php get_header(); ?>
Shows Footer.php file content<?php get_footer(); ?>
Shows Sidebar.php file content<?php get_sidebar(); ?>
Shows Comment.php file content <?php comments_template(); ?>

Cheat Sheet For WordPress Loop

The template tags below are generally used inside the WordPress loop for features such as displaying content, excerpts, and Metadata from the posts.

Shows the Content of Website Post<?php the_content(); ?>
Shows the Content of the Website Post<?php the_excerpt(); ?>
Title of Any Specific Post<?php the_title(); ?>
Link of Any Specific Post<?php the_permalink() ?>
Category of Any Specific Post<?php the_category(‘, ‘) ?>
Author of Any Specific Post<?php the_author(); ?>
ID of Any Specific Post<?php the_ID(); ?>
Edit link for Posts*<?php edit_post_link(); ?>
URL of the next page<?php next_post_link(‘ %link ‘) ?>
URL of the previous page<?php previous_post_link(‘%link’) ?>

The template tag for editing a post is only available to logged-in users who have editing privileges.

Template Tags for Sidebars

Themes on WordPress have sidebars with multiple widgets to make your utilization of the website even swifter. Through sidebars, you can drag and drop WP widgets. However, for each theme, the location of sidebars differs as well as the locations of widgets in the sidebar.

Here, we have mentioned a list of template codes that will let you get the sidebar in your website theme.

<?php if ( ! is_active_sidebar( ‘sidebar-1’ ) ) {return;}?>
<aside id=”secondary” class=”widget-area” role=”complementary”>
<?php dynamic_sidebar( ‘sidebar-1’ ); ?>
</aside><!– #secondary –>

Template Tags For Displaying Navigation Menu

The menu maintenance system that comes in WordPress in really strong yet easy to use. It even allows the users to customize the navigation menu as per their requirements for the WordPress websites. Moreover, one theme in WP may have multiple locations for the navigation menu.

Here is the cheat code that will let you find the location of the navigation menu without any hassle.

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

Miscellaneous Template Cheat Codes

We have created a list of template tags that are used very commonly for WordPress themes. Have a look!

Displays the date a post was written<?php echo get_the_date(); ?>
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 user’s gravatar through email address<?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/Cheats For WordPress Themes

There are conditional tags that you can use all over the WordPress theme or plugin in case you need to check if specific conditions are being met.

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

Through this, you can display a default featured image for a post that does not contain any featured image. See below for more conditional tags:

To check if a single post is displayingis_single()
To check if a page is displayingis_page()
To check if main blog page is displayedis_home()
To check if a static front page is displayedis_front_page()
To check if the main blog page is displayedTo check if a current viewer is logged in

WordPress Loop Cheat Sheet

WordPress Loop defines as the code that is highly used to fetch and show posts on WordPress websites. There are multiple template tags that only work inside the WordPress loop. The reason for it is that these tags are connected with specific post_type objects or a certain post.

You can find the cheat sheet for simple loops below:

To Check if there are any posts that match the query˂php if (have_posts()) : ?˃
If there are posts matching the query and then start the loop˂php while ( have_posts() ) : the_post();?˃
the code between the while loop will be repeated for each post˂php <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> ?˃
Stop the loop when all posts are being displayed˂?php endwhile; ?˃
If no posts are found˂?php else :?>
<p>Sorry no posts matched your criteria.</p>
<?php endif;?>

These are the shortcuts that will simplify your work and save a lot of time while you are working on WordPress website. Furthermore, your workflow will improve amazingly. Follow these cheat sheet and increase your productivity as well as the scalability of your WordPress website.