WordPress
Cheat Sheet
Most common functions, commands,
and keyboard shortcuts to help you with
your WordPress theme development
journey.
WP-CLI
WordPress Themes Development
WordPress Keyboard Shortcuts
03
05
10
Table of Contents
WordPress Cheat Sheet 2
WebsiteSetup.org - WordPress Cheat Sheet
WP-CLI Cheat Sheet
Download WordPress
Generate wp-config.php file.
Install WordPress
Search plugin
Install plugin
List plugins
List installed themes
Search for new themes
WP-CLI is the command-line interface for WordPress. You can update plugins, configure multisite
installations and much more, without using a web browser.
wp core download
wp core config --dbname=<dbname>
--dbuser=<dbuser> --dbpass=<dbpass>
--dbprefix=<dbprefix>
wp core install --url=”your_domain_name”
--title=”Your Blog Title” --admin_user=”admin”
--admin_password=”your_password”
--admin_email=”your_email”
wp plugin search yoast
wp plugin install pluginname
wp plugin list
wp theme list
wp theme search keyword
WordPress Cheat Sheet 3
WebsiteSetup.org - WordPress Cheat Sheet
Install theme
Activate theme
List posts
Edit post
Post update
Create posts
Login WordPress db
List WordPress users
Change WordPress post author
Optimize db
wp theme install bootstrap-four
wp theme activate bootstrap-four
wp post list
wp post edit 1
wp post update 1
--post_title=
”Your New title...”
wp post create
--post_status=publish
--post_title=”Second Post”
--edit
wp db cli
wp db query “SELECT user_login, ID FROM wp_users;”
wp post update 6 --post_author=1
wp db optimize
WordPress Cheat Sheet 4
WebsiteSetup.org - WordPress Cheat Sheet
Update WordPress
Update WordPress DB
Update all plugins
wp core update
wp core update-db
wp plugin update --all
WordPress Themes Development
Cheat Sheet
WordPress Theme Definition
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: http://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 Cheat Sheet 5
WebsiteSetup.org - WordPress Cheat Sheet
WordPress Template Files
Basic files every WordPress theme should have:
style.css
index.php
single.php
archive.php
searchform.php
search.php
404.php
comments.php
footer.php
header.php
sidebar.php
page.php
// Theme’s main stylesheet file
// Main template file
// Single post file.
// ..Used for to display single posts only
// Archive or Category template file
// Search form file
// Search results file
// 404 error page file.
// ..Will be displayed if no page can be found.
// Comments template file
// Footer content file
// Header content file
// Sidebar content file
// Single page file. Used for pages only.
WordPress Template Anatomy
header.php
The Loop
get_header();
wp_nav_menu();
//(registered in functions.php)
get_search_form();
index.php
home.php
archive.php
page.php
single.php
comments_template();
search.php
author.php
404.php
sidebar.php
get_sidebar()
footer.php
get_footer()
WordPress Cheat Sheet 6
WebsiteSetup.org - WordPress Cheat Sheet
Not Displayed
style.css
functions.php
comments.php
// Theme style
// Theme functions
// Comments template
WordPress Template Tags
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()
the_excerpt()
the_title()
the_permalink()
the_category(‘, ‘)
the_author()
the_ID()
edit_post_link()
next_post_link(‘%link’)
previous_post_link(‘%link’)
get_links_list()
wp_list_pages()
wp_get_archives()
wp_list_cats()
get_calendar()
wp_register()
wp_loginout()
Get post content
Get the post excerpt
Get the title of the post
Display post link
Display category of a post
Show post author
Display post ID
Show Edit link for a post
Display next page URL
Display previous page URL
Retrieve blogroll links
Retrieve all pages
Retrieve archive for the site
Retrieve all categories
Show the built-in WordPress calendar
Show register link
Displays login or logout links (for registered
users)
WordPress Cheat Sheet 7
WebsiteSetup.org - WordPress Cheat Sheet
Include Tags
Useful Header Functions
<?php get_header(); ?>
<?php
get_sidebar(); ?>
<?php
get_footer(); ?>
<?php
comments_template(); ?>
site_url()
wp_title()
bloginfo(‘name’)
bloginfo(‘description’)
get_stylesheet_directory_uri()
bloginfo(‘atom_rul’)
bloginfo(‘rss2_url’)
Use these tags to include templates to your theme.
Includes header.php and display its content
Includes sidebar.php
Includes the footer.php
Load specific template for comments
Get WordPress site url
Get page title
Get blog name
Get blog description
Get stylesheet directory URI
Get Atom feed 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 Cheat Sheet 8
WebsiteSetup.org - WordPress Cheat Sheet
WordPress Menu and Sidebars
Default Navigation Menu
Specific Navigation Menu
Category Based Navigation
Page Based Navigation
<?php wp_nav_menu(); ?>
<?php wp_nav_menu( array(‘menu’ => My 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>
<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>
Registering New Sidebar
add_action( ‘widgets_init’, ‘theme_slug_widgets_init’ );
function theme_slug_widgets_init() {
register_sidebar( array(
‘name’ => ( ‘My Sidebar’, ‘theme-slug’ ),
‘id’ => ‘sidebar-1’,
‘description’ => ( ‘Description’, ‘theme-slug’ ),
‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</li>’,
‘before_title’ => ‘<h2 class=”widgettitle”>’,
‘after_title’ => ‘<h2>’,
));
}
Add the following code to your functions.php file to register a new sidebar.
WordPress Cheat Sheet 9
WebsiteSetup.org - WordPress Cheat Sheet
Windows/Linux: Alt + Shift + Key”.
Mac: “Ctrl + Option (alt) + Key”. (WordPress 4.2 below use “Alt + Shift + Key”).
n Check Spelling (This requires a plugin.)
l Align Left
j Justify Text
c Align Center
d Strikethrough
r Align Right
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
WordPress Keyboard Shortcuts
Alt
+ +
Shift Key
WordPress Cheat Sheet 10
WebsiteSetup.org - WordPress Cheat Sheet
Windows and Linux: “Ctrl + Key”,
Mac: “Command + Key”.
Formatting Shortcuts while using visual editor.
c Copy
v Paste
a Select all
x Cut
z Undo
y Redo
b Bold
i Italic
u Underline
k Insert/edit link
* 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
Formatting Shortcuts
+
Ctrl Key
WordPress Cheat Sheet 11
WebsiteSetup.org - WordPress Cheat Sheet