Cheat Sheets Wordpress
WordPress Developer Super Cheat Sheet
There sure is a lot you need to remember when working with WordPress theme files.
From the names of basic template files to functions and how the WordPress Loop works, it’s next to impossible to remember every PHP tag or even how to define a new theme.
Theme Files
These are the basic files that every theme should include:
style.css– This is your theme’s stylesheet file.index.php– This is the main body template for your theme. Its job is to bring together all the information in the other theme files using template tags.header.php– This file contains the header information that appears with the<head>section of your site, stuff like metadata and the link to your stylesheet.sidebar.php– Everything in you sidebar goes in this file, like widgets, categories, additional menus, search form, etc.footer.php– This file contains your footer information, such as copyright details, widgets, and social icons.single.php– This file displays just one post.page.php– When you create a page on your site, this is the template responsible.comments.php– This file is responsible for displaying comments.404.php– When visitors try to visit a page on your site that doesn’t exist, this file will general an error page.functions.php– This file is where you can place special functions. We always recommend creating a child theme rather than edit this file directly.archive.php– Display an archive with this file so visitors to your site can go way back when and read your Hello World! post.search.php– Help your visitors search your site with this page.searchform.php– Display a search form for your visitors with this template file.
Defining a New Theme
Your stylesheet doesn’t just contain styling information for your theme – it also holds details about your theme that are displayed in the Appearance > Themes section of your WordPress admin.
The following is an example of the first few lines of the stylesheet for the default Twenty Sixteen theme:
| /* |
| Theme Name: Twenty Sixteen |
| Theme URI: https://wordpress.org/themes/twentysixteen/ |
| Author: the WordPress team |
| Author URI: https://wordpress.org/ |
| Description: Twenty Sixteen is a modernized take on an ever-popular WordPress layout — the horizontal masthead with an optional right sidebar that works perfectly for blogs and websites. It has custom color options with beautiful default color schemes, a harmonious fluid grid using a mobile-first approach, and impeccable polish in every detail. Twenty Sixteen will make your WordPress look beautiful everywhere. |
| Version: 1.2 |
| License: GNU General Public License v2 or later |
| License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| Tags: black, blue, gray, red, white, yellow, dark, light, one-column, two-columns, right-sidebar, fixed-layout, responsive-layout, accessibility-ready, custom-background, custom-colors, custom-header, custom-menu, editor-style, featured-images, flexible-header, microformats, post-formats, rtl-language-support, sticky-post, threaded-comments, translation-ready |
| Text Domain: twentysixteen |
| 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. |
| */ |
This information goes at the top of your stylesheet.css file.
Template Include Tags
Template include tags are used within one template file (for example index.php) to include (or call) the HTML and PHP found in another template file (for example header.php). While PHP has its own built-in include() statement to do this, these WordPress-specific tags make life much easier:
<?php get_header(); ?>– Includes the header.php file<?php get_sidebar(); ?>– Includes the sidebar.php file<?php get_footer(); ?>– Includes the footer.php file<?php comments_template(); ?>– Includes your comments
Template Header/Bloginfo Tags
These are functions you’ll find in your theme’s header.php file, though you’ll also find them in other theme files:
<?php bloginfo('name'); ?>– The title of your site, or blog name<?php bloginfo('url'); ?>– Your site’s URL<?php bloginfo('stylesheet_url'); ?>– Link to your themes’s stylesheet file<?php bloginfo('template_url'); ?>– Location of your site’s theme file<?php bloginfo('description'); ?>– Displays the tagline of your blog as set in Settings > General.<?php bloginfo('atom_url'); ?>– Link to your site’s atom URL<?php bloginfo('rss2_url'); ?>– RSS feed URL for your site<?php bloginfo('pingback_url'); ?>– Pingback URL for your site<?php bloginfo('version'); ?>– WordPress version number<?php bloginfo('html_type'); ?>– The HTML version your site is using<?php site_url(); ?>– The root URL for your site<?php get_stylesheet_directory(); ?>– Location of your stylesheet folder<?php wp_title(); ?>– Title of a specific page
Template Tags
<?php the_content(); ?> – Displays the content of a post<?php the_excerpt(); ?> – Displays the excerpt used in posts<?php the_title(); ?> – Title of the specific post<?php the_permalink() ?> – Link of a specific post<?php the_category(', ') ?> – Category of a specific post<?php the_author(); ?> – Author of a specific post<?php the_ID(); ?> – ID of a specific post<?php edit_post_link(); ?> – Edit link for a post<?php next_post_link(' %link ') ?> – URL of the next page<?php previous_post_link('%link') ?> – URL of the previous page<?php get_links_list(); ?> – Lists all links in blogroll<?php wp_list_pages(); ?> – Lists all pages<?php wp_get_archives() ?> – List archive for the site<?php wp_list_cats(); ?> – Lists all categories<?php get_calendar(); ?> – Displays the built-in calendar<?php wp_register(); ?> – Displays register link<?php wp_loginout(); ?> – Displays login/logout link only to registered users
The Loop
The Loop is the default mechanism in WordPress for displaying all of your posts. Exactly how many posts are retrieved is determined by the number of posts you’ve chosen to display in the “Reading” settings in your WordPress dashboard.
Within the Loop, WordPress loops through each post retrieved for the current page one at a time and formats it according to your theme’s instructions.
You can use the Loop to do a lot of useful stuff, like:
- Display post titles and excerpts on your homepage;
- Display the content and comments on a single post;
- Display the content on an individual page using template tags; and
- Display data from custom post types and custom fields.
| <?php |
| if ( have_posts() ) : |
| while ( have_posts() ) : |
| the_post(); |
| // |
| // Post Content here |
| // |
| endwhile; // end while |
| endif; // end if |
| ?> |
The Loop can display lots of different element for each post. Some of the most common template tags used in themes (according to the WordPress Theme Handbook) are:
next_post_link()– A link to the post published chronologically after the current postprevious_post_link()– A link to the post published chronologically before the current postthe_category()– The category or categories associated with the post or page being viewedthe_author()– The author of the post or pagethe_content()– The main content for a post or pagethe_excerpt()– The first 55 words of a post’s main content followed by an ellipsis (…) or read more link that goes to the full post. You may also use the “Excerpt” field of a post to customize the length of a particular excerpt.the_ID()– The ID for the post or pagethe_meta()– The custom fields associated with the post or pagethe_shortlink()– A link to the page or post using the URL of the site and the ID of the post or pagethe_tags()– The tag or tags associated with the postthe_title()– The title of the post or pagethe_time()– The time or date for the post or page. This can be customized using standard php date function formatting.
You can also use conditional tags, such as:
is_home()– Returns true if the current page is the homepageis_admin()– Returns true if an administrator is logged in and visiting the siteis_single()– Returns true if the page is currently displaying a single postis_page()– Returns true if the page is currently displaying a single pageis_page_template()– Can be used to determine if a page is using a specific template, for example:is_page_template('about-page.php')is_category()– Returns true if page or post has the specified category, for exampleis_category('news')is_tag()– Returns true if a page or post has the specified tagis_author()– Returns true if a specific author is logged in and visiting the siteis_search()– Returns true if the current page is a search results pageis_404()– Returns true if the current page does not existhas_excerpt()– Returns true if the post or page has an excerpt
Wordpress Cheat sheet
Theme Headers style.css
/** * Theme Name: My theme (required) * Template: The name of the parent theme. E.g. Twenty Seventeen * Description: A short description of the theme. * * Theme URI: Subject URL. E.g. http://wordpress.org/themes/twenty * Author: Kama * Author URI: https://wp-kama.com * * Tags: black, brown, orange * Text Domain: Subject translation domain. E.g. twentythirteen * * License: License. E.g. GNU General Public License v2 or later * License URI: http://www.gnu.org/licenses/gpl-2.0.html * * Version: 1.0 */
.htaccess code
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Theme Files (include)
- <?php get_header(); ?>header.php.
- <?php get_template_part('file'); ?>file.php.
- <?php get_search_form(); ?>Search form searchform.php.
- <?php comments_template(); ?>Comments form comments.php.
- <?php get_sidebar(); ?>sidebar.php.
- <?php get_footer(); ?>footer.php.
- get_template_directory()The path to the parent theme (not child). No trailing /.
- get_stylesheet_directory()Theme Path (where parent/child style.css). No trailing /.
- get_parent_theme_file_path()File path of parent theme (not child).
- get_theme_file_path()File path of parent/child theme.
- load_template()Includes file (require_once).
- locate_template()Finds/Includes parent/child theme file.
- get_template_directory_uri()URL of parent theme (not child). No trailing /.
- get_stylesheet_directory_uri()Theme URL (child theme if it exists). No trailing /.
- get_theme_root_uri()URL of the theme's DIR. No trailing /.
- get_stylesheet_uri()URL of the theme's style.css file.
- get_theme_file_uri()URL of the parent/child theme file.
- get_parent_theme_file_uri()URL of the parent theme file.
Theme Files (hierarchy) /themes/THEME/
- style.cssTheme styles file (required)
- index.phpAny page without a template file (required)
- front-page.phpFront (Home) page
- home.phpPosts page (or Home page)
- functions.phpA special file for php functions (code)
- 404.phpPage "not found"
- comments.phpComments Template (part)
- header.phpSite Header Template (part)
- searchform.phpSearch Form Template (part)
- sidebar.phpSidebar Template (part)
- footer.phpSite Footer Template (part)
- single.phpPost page post_type = post
- single-POST_TYPE.phpPost page post_type = POST_TYPE
- single-POST_TYPE-POST_NAME.phpPost page with POST_NAME and POST_TYPE
- singular.phpPost of any post type
- page.phpPage post_type = page
- page-POST_NAME.phpPage post_name = POST_NAME
- page-ID.phpPage ID = ID
- attachment.phpAny attachment page
- image.phpImage attachment page
- archive.phpPage of any archive
- archive-POST_TYPE.phpPage of post type archive
- search.phpSearch page
- category.phpAny Category page
- category-SLUG.phpCategory page with slug = SLUG
- category-ID.phpCategory page with term_id = id
- tag.phpAny Tag page
- tag-SLUG.phpTag page with slug = SLUG
- tag-ID.phpTag page with term_id = id
- taxonomy.phpAny custom taxonomy element page
- taxonomy-TAXONOMY.phpPage of any term of TAXONOMY taxonomy
- taxonomy-TAXONOMY-SLUG.phpPage of SLUG term of TAXONOMY taxonomy
- author.phpPage of Author posts
A post template from any file:
<?php /* Template Name: My page template Template Post Type: post, page, product */ // … template file code
Site Information bloginfo
- bloginfo()Displays information about the site.
- get_bloginfo()Gets information about the site.
- <?php bloginfo('name'); ?>Site name.
- <?php bloginfo('description'); ?>Short description of the site.
- <?php bloginfo('template_url'); ?>Theme URL: get_template_directory().
- <?php bloginfo('template_directory'); ?>Same as template_url.
- <?php bloginfo('stylesheet_directory'); ?>Theme URL: get_stylesheet_directory_uri().
- <?php bloginfo('stylesheet_url'); ?>Theme file style.css URL: get_stylesheet_uri().
- <?php bloginfo('charset'); ?>The site's encoding: UTF-8.
- <?php bloginfo('html_type'); ?>Content-Type of the page: text/html.
- <?php bloginfo('language'); ?>Site locale (language): RU.
- <?php bloginfo('version'); ?>WordPress version: 5.5.3.
- <?php bloginfo('rss2_url '); ?>URL of the feed: /feed.
- <?php bloginfo('comments_rss2_url'); ?>URL of the comments feed: /comments/feed.
- <?php bloginfo('admin_email'); ?>E-mail of Admin.
- <?php bloginfo('pingback_url'); ?>Notification URL to the xmlrpc.php file.
- <?php bloginfo('rdf_url'); ?>RDF/RSS 1.0 feed URL (/feed/rfd).
- <?php bloginfo('rss_url'); ?>RSS 0.92 feed URL (/feed/rss).
- <?php bloginfo('atom_url '); ?>Atom feed URL (/feed/atom).
- <?php bloginfo('url'); ?>Home page URL. Alias home_url().
- <?php bloginfo('wpurl'); ?>Admin panel URL. Alias site_url().
Comment Loop
- comment_ID()Displays the ID of the current comment.
- comments_popup_link()Displays <a> link to the comment popup.
- comment_text()Displays the text of the comment.
- comment_author()Displays the comment author name.
- comments_link()Displays a URL to the post comment form.
- comment_reply_link()Displays a <a> link that allows you to reply to comments.
- comment_time()Displays the comment publishing time.
- comment_author_link()Displays the comment author's name as a link.
- comment_author_url()Displays comment author URL (sets when commenting).
- comment_author_url_link()Displays comment author link (A tag).
- comment_author_email_link()Displays comment author email as a mailto link.
- edit_comment_link()Displays edit comment link.
The Loop
- in_the_loop()Checks if the WordPress loop is active.
- have_posts()Checks if there are posts for the loop.
- the_post()Sets the next post in the loop and global $post.
- setup_postdata()Sets global $post.
- the_ID()Displays the ID of the current post.
- the_title()Displays current post title.
- the_title_attribute()Displays post title for html tag attribute.
- the_content()Displays post content.
- the_excerpt()Displays the excerpt (quote) of the post, with [...] at the end.
- the_excerpt_rss()Displays the excerpt (quote) (for RSS).
- get_permalink()Gets post URL.
- the_permalink()Displays post URL.
- comments_number()Displays post's number of comments.
- edit_post_link()Displays edit post link (A html tag).
- the_date()Displays/retrieves post publication date.
- get_the_date()Gets the post creation date.
- the_time()Displays post publication date.
- get_post_time()Gets time (date) of post publication.
- the_modified_date()Displays time (date) when post was changed.
- the_post_thumbnail()Displays html code of post thumbnail image.
- get_post_thumbnail_id()Gets the post thumbnail ID.
- has_post_thumbnail()Whether or not the post has a thumbnail. Conditional tag.
- the_post_thumbnail_url()Displays the URL of the post thumbnail.
- the_attachment_link()Displays the link (A tag) of the attachment or the attachment page.
- get_attachment_link()Gets the URL to the attachment page.
- wp_get_attachment_link()Gets the link (A tag) of the attachment or the attachment page.
- the_tags()Displays links to the post tags.
- the_category()Displays post categories as links.
- the_taxonomies()Displays links <a> to the post terms.
- in_category()Checks if the post belongs to a category.
- sticky_class()Displays a "sticky" class if it is a sticky post.
- is_sticky()Checks if the post is sticky to the home page.
- the_meta()Displays post meta-fields in <li> list.
- get_post_format()Gets the post format: quote, status, video, audio.
- the_author()Displays post's author name.
- get_the_author()Gets post's author name (display_name).
- the_author_link()Displays link (A tag) to the site of post's author.
- get_the_author_link()Gets link (A tag) to the site of post's author.
- the_author_posts()Displays the total number of posts written by the author.
- the_author_posts_link()Displays link (A tag) to the post author's archive page .
- the_author_meta()Displays specified meta-field of the post author (wp user).
- get_the_author_meta()Gets specified meta-field of the post author (wp user).
- the_modified_author()Displays the name of the author who last modified the post.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- Post output, loop functions: the_title(), etc. --> <?php endwhile; else: ?> No posts. <?php endif; ?>
<?php if ( have_posts() ){ while ( have_posts() ){ the_post(); ?>
<!-- Post output, loop functions: the_title(), etc. -->
<?php } } else { ?>
No posts.
<?php } ?>
<?php while ( have_posts() ){ the_post(); ?>
<!-- Post output, loop functions: the_title(), etc. -->
<?php } ?>
<?php if ( ! have_posts() ){ ?>
No posts.
<?php } ?>
<?php
global $post;
$myposts = get_posts([
'numberposts' => 5,
'offset' => 1,
'category' => 1
]);
if( $myposts ){
foreach( $myposts as $post ){
setup_postdata( $post );
?>
<!-- Post output, loop functions: the_title(), etc. -->
<?php
}
} else {
// No posts found
}
wp_reset_postdata(); // Reset $post
?>
<?php
global $post;
$query = new WP_Query( [
'posts_per_page' => 5,
'orderby' => 'comment_count',
] );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
?>
<!-- Post output, loop functions: the_title(), etc. -->
<?php
}
} else {
// No posts found
}
wp_reset_postdata(); // Reset $post
?>
WP CLI
Core:
# Download WordPress wp core download --locale=ru_RU # Generate wp-config.php: wp core config --dbname=NAME --dbuser=USER --dbpass=PASS --dbprefix=wp_ # Create DB (based on wp-config.php) wp db create # Install WP to created DB wp core install --url=example.com --title=Example --admin_user=supervisor \ --admin_email=info@example.com --admin_password=strongpassword
Post:
# List posts: wp post list # Edit post: wp post edit 1 # Post update: wp post update 1 --post_title="Your New title..." # Create posts: wp post create --post_status=publish --post_title="Second Post" --edit
Post meta:
# See all metas of post 18: wp post meta list 18 # Get post meta value: wp post meta get 18 meta_name # Delete post meta by key: wp post meta delete 18 meta_name
DB:
# Create DB dump wp db export - --add-drop-table --default-character-set=utf8mb4 | gzip > ./db-dump-$(date +%Y-%m-%d-%H%M%S).sql.gz # Insert data from DB dump to DB wp db import db_backup-2022-01-20.sql # Login WordPress db: wp db cli # Run SQL Query: wp db query "SELECT user_login, ID FROM wp_users;" # Optimize db: wp db optimize
Update:
# Update WordPress wp core update # Update all plugins: wp plugin update --all
Themes & Plugins
# List plugins: wp plugin list # Search plugin: wp plugin search yoast # Install plugin: wp plugin install yoast # List installed themes: wp theme list # Install theme: wp theme install twentyone # Activate theme: wp theme activate twentyone
Plugin Headers
<?php /** * Plugin Name: My Plugin * Description: Description of the plugin (140 characters) * * Plugin URI: URL to info about plugin * Author URI: https://wp-kama.com * Author: Kama * * Text Domain: Translation ID. E.g. my-plugin * Domain Path: Path to MO file (relative to plugin folder) * * Requires PHP: 7.0 * Requires at least: 5.7 * * License: GPL2 * License URI: https://www.gnu.org/licenses/gpl-2.0.html * * Network: true - activates the plugin for the whole network * Update URI: https://example.com/link_to_update * * Requires Plugins: some-plugin, some-plugin-2 * * Version: 1.0 */ // plugin code
Plugin
- register_activation_hook()Registers the function to activate the plugin.
- register_deactivation_hook()Registers the function to deactivate the plugin.
- register_uninstall_hook()Registers the function for deleting the plugin.
- plugins_url()Gets URL of plugins/mu plugins folder (no slash at the end)**.
- plugin_basename()Path to plugin file (from plugins folder).
- plugin_dir_path()Gets Path to plugin folder (has slash at the end).
- plugin_dir_url()Gets URL of the plugin folder (has slash at the end).
- get_plugins()Gets data of plugins (active and inactive).
- get_plugin_data()Gets data of the plugin from file headers.
- activate_plugins()Activates plugins.
- deactivate_plugins()Deactivates plugins.
- is_plugin_active()Checks if a plugin is active. Works only in the admin panel.
<?php
if( ! defined('WP_UNINSTALL_PLUGIN') ) exit;
// the check passed successfully. Starting from here remove all plugin data (options, db tables etc.).
delete_option( 'plug_option' );
Script and Style
- wp_register_script()Registers the js file.
- wp_enqueue_script()Registers and connects the js file.
- wp_dequeue_script()Deletes file from the output queue.
- wp_add_inline_script()Adds JS code to the registered script.
- wp_deregister_script()Unregisters the js file.
- wp_script_add_data()Adds data to the script. Example: script only for "IE 6", "lt IE 9".
- wp_localize_script()Adds data before the specified script.
- wp_script_is()Whether the file has been registered/waiting for output.
- wp_register_style()Registers the css file.
- wp_enqueue_style()Registers and connects the css file.
- wp_dequeue_style()Deletes file from the output queue.
- wp_add_inline_style()Adds styles directly to the html document.
- wp_deregister_style()Unregisters the css file.
- wp_style_add_data()Adds data to styles. Example: styles only for "IE 6", "lt IE 9".
- wp_style_is()Whether the file has been registered/waiting for output.
add_action( 'wp_enqueue_scripts', 'add_my_scripts' ); // Front
add_action( 'admin_enqueue_scripts', 'add_my_scripts' ); // Admin
add_action( 'login_enqueue_scripts', 'add_my_scripts' ); // wp-login.php
function add_my_scripts(){
if ( ! wp_script_is( 'my-script', 'enqueued' ) ) {
// The my-script is not added to the queue
}
if ( ! wp_style_is( 'my-style', 'registered' ) ) {
// Styles my-script is not registered
}
wp_enqueue_script( 'my-script', 'src', ['deps'], '1.0', 'in_footer' );
wp_enqueue_style( 'my-style', 'src', ['deps'], '1.0', 'all' );
wp_enqueue_style( 'theme-style', get_stylesheet_uri() ); // theme style.css
wp_localize_script( 'my-script', 'myajax', [
'ajaxurl' => admin_url( 'admin-ajax.php' )
] );
wp_script_add_data( 'my-script', 'conditional', 'lt IE 9' );
wp_style_add_data( 'my-style', 'conditional', 'lt IE 9' )
wp_add_inline_script( 'my-scripts', 'alert("Hello!");' );
wp_add_inline_style( 'my-style', '
.mycolor{
background: #fff;
}
');
wp_deregister_script( 'my-script' );
wp_deregister_style( 'my-style' );
}
Hooks Functions
- add_action()Hangs a function on an event.
- remove_action()Deletes a function from the event.
- did_action()Gets a number of how many times the event was performed.
- do_action()Creates an event.
- do_action_ref_array()Creates an event. Arguments are passed in an array.
- has_action()Checks whether a function is hung on the event.
- current_action()Gets the name of the current event.
- doing_action()Checks if the event is being processed at the moment.
- remove_all_actions()Deletes all functions attached to the event.
- add_filter()Hangs a function on a filter.
- remove_filter()Deletes a function from the filter.
- apply_filters()Creates a filter.
- apply_filters_ref_array()Creates a filter. Arguments are passed in an array.
- has_filter()Checks whether the function is hung on the filter.
- current_filter()Gets the name of the current filter.
- doing_filter()Checks if the filter is currently being processed.
- remove_all_filters()Deletes all functions attached to the filter.
function my_filter_function( $str ){
return 'Hello '. $str;
}
// Let's attach a function to the filter
add_filter( 'my_filter', 'my_filter_function' );
// Call the filter
echo apply_filters( 'my_filter', 'John' ); //> Hello John
// Create a function for the event
function my_action_function( $text ){
echo 'The my_action event has been triggered just now.';
}
// Let's attach the function to the my_action event
add_action( 'my_action', 'my_action_function' );
// Action call
do_action( 'my_action' ); //> The my_action event has been triggered just now.
Localization (translation)
- __()Gets string translation.
- _e()Outputs a string translation.
- _n()Gets a string translation after a number.
- esc_attr__()Gets string translation + esc_attr().
- esc_attr_e()Outputs the string translation + esc_attr().
- esc_html__()Gets the string translation + esc_html().
- esc_html_e()Outputs the string translation + esc_html().
- _x()Gets the string translation for context.
- _ex()Outputs the string translation for the context.
- _nx()Gets a string translation after a number for the context.
- date_i18n()Gets the translated date. Localization for date().
- determine_locale()Gets the locale of the site suitable for the current query.
- get_locale()Gets the locale of the site. E.g. en_US.
- get_user_locale()Gets the user's locale.
- switch_to_locale()Switches the user's locale.
- is_locale_switched()Checks if switch_to_locale() was used.
- load_plugin_textdomain()Loads .mo file from plugin folder.
- load_muplugin_textdomain()Loads .mo file from plugin's MU folder.
- load_theme_textdomain()Loads the .mo file from the theme folder.
- load_child_theme_textdomain()Loads the .mo file from the child theme folder.
- load_textdomain()Loads the specified .mo file from any folder.
- is_textdomain_loaded()Checks if the .mo file is loaded.
- unload_textdomain()Unloads (removes) the loaded .mo file.
Conditional tags (post types and queries)
if( is_single() ){
// single post type page
}
- wp_doing_ajax()Works for an AJAX request in WordPress.
- wp_doing_cron()Works for WordPress cron requests.
- is_ssl()Works for HTTPS (SSL).
- is_front_page()Home page.
- is_home()Posts page (or Home page).
- is_single()Page of post of any type except: attachment and page.
- is_singular()Page of post of any type.
- is_page()The page of a Static page.
- is_page_template()Whether or not a template file is used for the page.
- is_attachment()Attachment page.
- is_search()Search result page.
- is_archive()Archive page: category, tag, author, date.
- is_category()Category page.
- is_tag()Tag page.
- is_tax()Page of custom taxonomy.
- is_post_type_archive()Page of custom post type archive.
- is_author()Page of author posts archive.
- is_date()Archive page by date.
- is_year()Archive page by Year.
- is_month()Archive page by Month.
- is_day()Archive page by Day.
- is_time()Archive page by an hour, minute, second.
- is_paged()Pagination page.
- is_404()"Not found" page.
- is_preview()Post preview page.
- is_feed()Feed page.
- is_admin()Admin panel.
- is_network_admin()Administration panel "Network management" of Multisite sites.
- is_blog_admin()Section of the admin panel of a separate site in Multisite.
- is_user_admin()The "User" section of the admin panel in Multisite.
- is_customize_preview()Page of customizer in the admin area.
- is_robots()Query to the robots.txt file.
- is_embed()Page of embedding post.
- is_comment_feed()Comments feed page.
- is_trackback()Page of pings (trackback).
Conditional tags (others)
if( is_user_logged_in() ){
// user is authorized
}
- is_user_logged_in()Checks if the user is logged in.
- have_comments()Checks if there are comments to be displayed on the page.
- comments_open()Checks if comments are opened.
- has_category()Checks if the post is in at least one category.
- has_tag()Checks if the post is in at least one tag.
- has_term()Checks if the post is in at least one taxonomy term.
- has_excerpt()Checks if the post has an excerpt (quote, short description).
- is_nav_menu()Checks if there is a menu by ID, slug or name.
- has_nav_menu()Checks if registered menu area have an attached menu.
- has_shortcode()Checks if content contains the specified shortcode.
- shortcode_exists()Checks if the specified shortcode is registered.
- in_category()Checks if the post are in a category.
- in_the_loop()Checks if we are inside a WP Loop.
- is_main_query()Checks if we are in the main WP Loop.
- is_active_sidebar()Checks if there is at least one widget in the widgets area.
- is_child_theme()Checks if a child theme being used.
- is_dynamic_sidebar()Checks if theme sidebars are enabled and they has at least one widget.
- is_local_attachment()Checks if the given URL is an attachment page.
- is_multisite()Checks if the multisite mode is turned on.
- is_new_day()Checks if the current date differs from the previous (in the loop).
- is_post_type_hierarchical()Checks if the post type is hierarchical (tree-like).
- is_taxonomy_hierarchical()Checks if the taxonomy is hierarchical (tree-like).
- is_sticky()Checks if the post is sticky (be shown on front page).
- pings_open()Checks if the post is allowed to receive pings.
- post_exists()Checks if there is a post with a specified title (post_title).
- taxonomy_exists()Checks if the specified taxonomy exist.
- post_password_required()Checks if the post is password protected and it is correct.
- term_exists()Checks if the taxonomy element exist (return the term ID).
- cat_is_ancestor_of()Checks if the category is child of another one (all nesting levels).
- term_is_ancestor_of()Checks if the term is child of another one (all nesting levels).
- wp_attachment_is()Checks if the attachment is an image, audio or video.
- wp_attachment_is_image()Checks if the attachment (post) is a image .
- is_header_video_active()Checks if the header video should be shown on the page.
- has_custom_header()Checks if the picture/video is set for the theme header.
- wp_is_mobile()Checks if the site is viewed on a mobile device.
- wp_is_post_autosave()Checks if the post is an auto-save.
- wp_is_post_revision()Checks if the post is a revision.
Template Tags
- home_url()Gets the URL of the homepage.
- site_url()Gets the URL of the admin panel.
- wp_get_document_title()Gets the page title for <title>.
- the_archive_title()Outputs the title of the archive page: tag, category, date.
- single_term_title()Outputs/Gets the title of the term page.
- single_post_title()Outputs/Gets title of a post page.
- single_cat_title()Outputs/Gets title of a category/tag page.
- body_class()Outputs css classes for the <body> tag.
- wp_body_open()Triggers the wp_body_open hook. Use is after <body> tag.
- wp_head()Triggers the wp_head hook. Use it in header.php file.
- wp_footer()Triggers the wp_footer hook. Use it in footer.php file.
- wp_list_categories()Outputs list of categories as links.
- wp_dropdown_categories()Outputs a dropdown list of categories/terms.
- wp_list_comments()Outputs/Gets post comments.
- comment_form()Outputs comment form.
- wp_tag_cloud()Outputs/Gets tag cloud.
- register_sidebar()Registers a widget panel.
- register_sidebars()Registers a widget panels (several at once).
- wp_nav_menu()Outputs a custom menu created in the admin panel.
- register_nav_menu()Registers a single menu location (area).
- register_nav_menus()Registers multiple menu locations (areas).
- wp_get_attachment_image()Gets image IMG tag.
- wp_get_attachment_image_src()Gets image data: URL/Width/Height.
- wp_get_attachment_image_url()Gets image URL by it's ID.
- category_description()Gets category description.
- term_description()Gets term description.
- get_the_term_list()Outputs a list of post terms as links.
- get_avatar()Gets image of the user avatar (<img> tag).
- next_post_link()Displays a link to the next most recent post (by date).
- previous_post_link()Displays a link to the previous most recent post (by date).
- get_post_type_archive_link()Gets the URL for the post type archive page.
- wp_link_pages()Outputs pagination for multi-page post <!--nextpage-->.
- the_post_navigation()Outputs links to next/previous posts (as HTML block).
- wp_get_archives()Outputs links to date archives pages: days, months, years.
- wp_login_form()Outputs login form HTML code.
- edit_tag_link()Outputs a link to edit the current tag.
- edit_term_link()Outputs a link to edit the current term.
Formatting
- absint()Convert a value to non-negative integer.
- antispambot()Converts all email characters to HTML entities.
- force_balance_tags()Fixes HTML tags: not closed, wrong syntax.
- links_add_target()Adds a target attr with the specified value to A tags.
- make_clickable()Changes links like http://site.com, www.site.com to HTML link.
- normalize_whitespace()Replaces all line breaks (EOL) with \n, removes extra spaces.
- number_format_i18n()Corrects integer or decimal number format to fit localisation.
- size_format()Changes bytes to format: 500 B, 63 KB, 9 MB, 2 GB, 1 TB.
- set_url_scheme()Fixs URL protocol. If set "relative" domain will be removed.
- wp_rel_nofollow()Adds rel="nofollow" to all <a>. Internal links are skipped.
- trailingslashit()Adds a slash (/) to the end of string (URL/path).
- untrailingslashit()Removes closing slash (/) at the end of a string.
- user_trailingslashit()Adds or removes a slash (/) at the end. Depends on WP permalink settings.
- wp_trim_words()Trims text to the specified number of words.
- wpautop()Replaces double newline (\n\n) with HTML <p>...</p> and single with <br>.
- wptexturize()Changes some characters in the text: (tm) >> ™ etc.
- zeroise()Add leading zeros when necessary: 10 >> 0010.
Escaping on output
- esc_attr()Cleans for use in HTML tag attribute.
- esc_html()Cleans for displaying text on the screen.
- esc_url()Cleans for use in the src=, url=, etc. attributes.
- esc_textarea()Cleans for use in <textarea> value.
- wp_strip_all_tags()Removes all HTML tags.
- wp_kses()Removes all HTML tags.
- esc_js()Prepares string for display in JS.
- esc_sql()Cleans the string, leaving only the specified HTML tags.
Sanitize on input
- sanitize_text_field()Cleans string, leaving only clean text: without HTML, extra spaces, etc.
- sanitize_textarea_field()Cleans string for textarea (when saving to the database).
- sanitize_key()Cleans string to use it as a key/ID.
- sanitize_url()Cleans string to use it for redirects or to store it in the DB.
- sanitize_html_class()Cleans the text for use in the HTML attribute "class".
- sanitize_email()Cleans string, leaving only the permissible characters for an email.
- sanitize_file_name()Cleans the file name, replacing " " with "_" and removing impermissible characters.
- sanitize_title_with_dashes()Cleans title, replacing " " with "-".
- sanitize_mime_type()Removes all characters except "-+**.a-zA-Z0-9/." - allowed in MIME type.