Most common functions, commands, and keyboard shortcuts to help you with your WordPress theme development journey.
WP-CLI Cheat Sheet
WP-CLI is the command-line interface for WordPress. You can update plugins, configure multisite installations and much more, without using a web browser.
Your theme’s information is stored in the theme’s main style.css file. The information is displayed when you view your theme on Appearance > Themes or on WordPress’ theme repository (if it’s submitted and approved).
/*
Theme Name: Twenty Seventeen
Theme URI: https://wordpress.org/themes/twentyseventeen/
Author: the WordPress team
Author URI: https://wordpress.org/
Description: Twenty Seventeen brings your site to life with immersive featured images and subtle animations. With a focus on business sites, it features multiple sections on the front page as well as widgets, navigation and social menus, a logo, and more. Personalize its asymmetrical grid with a custom color scheme and showcase your multimedia content with post formats. Our default theme for 2017 works great in many languages, for any abilities, and on any device.
Version: 1.0
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twentyseventeen
Tags: one-column, two-columns, right-sidebar, flexible-header, accessibility-ready, custom-colors, custom-header, custom-menu, custom-logo, editor-style, featured-images, footer-widgets, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/
WordPress Template Files
Basic files every WordPress theme should have:
style.css // Theme's main stylesheet file
index.php // Main template file
single.php // Single post file.
// ..Used for to display single posts only
archive.php // Archive or Category template file
searchform.php // Search form file
search.php // Search results file
404.php // 404 error page file.
// ..Will be displayed if no page can be found.
comments.php // Comments template file
footer.php // Footer content file
header.php // Header content file
sidebar.php // Sidebar content file
page.php // Single page file. Used for pages only.
WordPress Template Anatomy
header.php
get_header();
wp_nav_menu(); // (registered in functions.php)
get_search_form();
Template tags are used within themes to retrieve content from your database.
The content could be anything from a blog title to a complete sidebar.
Template tags are the preferred method to pull content into your theme because: they can print dynamic content; they can be used in multiple theme files; and they separate the theme into smaller, more understandable, sections.
the_content() Get post content
the_excerpt() Get the post excerpt
the_title() Get the title of the post
the_permalink() Display post link
the_category(', ') Display category of a post
the_author() Show post author
the_ID() Display post ID
edit_post_link() Show Edit link for a post
next_post_link('%link') Display next page URL
previous_post_link('%link') Display previous page URL
get_links_list() Retrieve blogroll links
wp_list_pages() Retrieve all pages
wp_get_archives() Retrieve archive for the site
wp_list_cats() Retrieve all categories
get_calendar() Show the built-in WordPress calendar
wp_register() Show register link
wp_loginout() Displays login or logout links (for registered users)
Include Tags
Use these tags to include templates to your theme.
<?php get_header(); ?> Includes header.php and display its content
<?php get_sidebar(); ?> Includes sidebar.php
<?php get_footer(); ?> Includes the footer.php
<?php comments_template(); ?> Load specific template for comments
Useful Header Functions
site_url() Get WordPress site url
wp_title() Get page title
bloginfo('name') Get blog name
bloginfo('description') Get blog description
get_stylesheet_directory_uri() Get stylesheet directory URI
bloginfo('atom_url') Get Atom feed URL
bloginfo('rss2_url') RSS 2.0 URL
The Loop
The Loop is the default mechanism WordPress uses for outputting posts through a theme’s template files.
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
// Display post content
<?php endwhile; ?>
<?php endif; ?>
WordPress Menu and Sidebars
Default Navigation Menu
<?php wp_nav_menu(); ?>
Specific Navigation Menu
<?php wp_nav_menu( array('menu' => My Navigation' )); ?>
n Check Spelling (This requires a plugin.)
l Align Left
j Justify Text
c Align Center
d Strikethrough
r Align Right
u o List
a Insert link
o 1. List
s Remove link
q Quote
m Insert Image
w Distraction Free Writing mode
t Insert More Tag
p Insert Page Break tag
h Help
x Add/remove code tag
1 Heading 1
2 Heading 2
3 Heading 3
4 Heading 4
5 Heading 5
6 Heading 6
9 Address
Ctrl + Key
Windows and Linux: “Ctrl + Key“, Mac: “Command + Key“.
c Copy
v Paste
a Select all
x Cut
z Undo
y Redo
b Bold
i Italic
u Underline
k Insert/edit link
Formatting Shortcuts
Formatting Shortcuts while using visual editor.
* Start an unordered list
- Start an unordered list
1. Start an ordered list
1) Start an ordered list
## H2
### H3
#### H4
##### H5
###### H6
> Transform text into blockquote
- – Horizontal line
`..` Transform text into code block
0 comments