WordPress V5.0+Template Tag Reference Guide as of Version 5.2
Presented by DBS > Interactive Development :
Include Tags
Comments Template comments_template();
Loads the comment template. For use in single Post and Page displays.
<?php comments_template($file, $separate_comments); ?>
$file
String • Default: '/comments.php'
(Optional) The file to load.
$separate_comments
Boolean • Default: false
(Optional) Whether to separate the comments by comment type.
Get Footer get_footer();
Includes the footer.php template file from your current theme's directory. If a name is specified then a specialized footer footer-{name}.php will be included. If the theme contains no footer.php file then the footer from the default theme wp-includes/theme-compat/footer.php will be included.
<?php get_footer($name); ?>
$name
String • Default: none
(Optional) Calls for footer-name.php.
Get Header get_header();
Includes the header.php template file from your current theme's directory. If a name is specified then a specialized header header-{name}.php will be included. If the theme contains no header.php file then the footer from the default theme wp-includes/theme-compat/header.php will be included.
<?php get_header($name); ?>
$name
String • Default: none
(Optional) Calls for header-name.php.
Get Search Form get_search_form();
Display search form using searchform.php Theme file.
<?php get_search_form(); ?>
No parameters.
Get Sidebarget_sidebar();
Includes the sidebar.php template file from your current theme's directory. If a name ($name) is specified then a specialized sidebar sidebar-{name}.php will be included. If the theme contains no sidebar.php file then the sidebar from the default theme wp-includes/theme-compat/sidebar.php will be included.
<?php get_sidebar($name); ?>
$name
String • Default: none
(Optional) Calls for sidebar-name.php.
Get Template Partget_template_part();
Loads a template part into a template (other than header, sidebar, footer). Makes it easy for a theme to reuse sections of code in an easy to overload way for child themes. Includes the named template part for a theme or if a name is specified then a specialized part will be included. If the theme contains no {slug}.php file then no template will be included. For the parameter, if the file is called "{slug}-{name}.php".
<?php get_template_part($slug, $name); ?>
$slug
String • Default: none
The slug name for the generic template.
$name
String • Default: none
(Optional) The name of the specialized template.
WP Enqueue Scriptwp_enqueue_script();
The safe and recommended method of adding JavaScript to a WordPress generated page is by using wp_enqueue_script(). This function includes the script if it hasn't already been included, and safely handles dependencies.
<?php wp_enqueue_script($handle, $src, $deps, $ver, $in_footer); ?>
$handle
String • Default: none
Name of the script. Lowercase string.
$src
String • Default: false
(Optional) URL to the script. Example: "http://example.com/wp-includes/js/scriptaculous/scriptaculous.js". This parameter is only required when WordPress does not already know about this script. You should never hardcode URLs to local scripts, use plugins_url() (for Plugins) and get_template_directory_uri() (for Themes) to get a proper URL.
$deps
Array • Default: array()
(Optional) Array of handles of any script that this script depends on (scripts that must be loaded before this script). False if there are no dependencies. This parameter is only required when WordPress does not already know about this script.
$ver
String • Default: false
(Optional) String specifying the script version number, if it has one, which is concatenated to the end of the path as a query string. If no version is specified or set to false then WordPress automatically adds a version number equal to the current version of WordPress you are running. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the script.
$in_footer
Boolean • Default: false
(Optional) Normally scripts are placed in the <head> section. If this parameter is true the script is placed at the bottom of the <body>. This requires the theme to have the wp_footer() hook in the appropriate place. Note that you have to enqueue your script before wp_head is run, even if it will be placed in the footer.
Add New List Items wp_meta();
By default, wp meta() is called immediately after wp_loginout() by sidebar.php and the Meta widget, allowing functions to add new list items to the widget.
<?php wp_meta(); ?>
Update PHP Annotation wp_update_php_annotation();
This function is to be used after wp_get_update_php_url() to display a consistent annotation if the web host has altered the default "Update PHP" page URL.
<?php wp_update_php_annotation($before, $after); ?>
$before
String • Default value: 'p class="description" '
(Optional) Markup to output before the annotation.
$after
String • Default value: 'p'
(Optional) Markup to output after the annotation.
Post Exists post_exists();
Determines if a post exists based on title, content, date and type.
<?php post_exists($title, $content , $date, $type); ?>
$title
String
(Required) Post title.
$content
String
(Optional) post content.
$date
String
(Optional) post date.
$type
String
(Optional) post type.
Download URL download_url();
Downloads a URL to a local temporary file using the WordPress HTTP API.
<?php download_url($url, $timeout , $date, $signature_verification); ?>
$url
String
(Required) The URL of the file to download.
$timeout
int • Default: 300
(Optional) The timeout for the request to download the file.
$signature_verification
bool • Default: false
(Optional) Whether to perform Signature Verification.
Translate User Role translate_user_role();
Since the role names are in the database and not in the source there are dummy gettext calls to get them into the POT file and this function properly translates them back. The before_last_bar() call is needed, because older installations keep the roles using the old context format: ‘Role name|User role’ and just skipping the content after the last bar is easier than fixing them in the DB. New installations won’t suffer from that problem.
<?php translate_user_role($name, $domain;) ?>
$name
String
(Required) The role name.
$domain
String• Default Value: default
(Optional) Text domain. Unique identifier for retrieving translated strings.
WP Trim Excerpt wp_trim_excerpt();
The excerpt word amount will be 55 words and if the amount is greater than that, then the string ‘ […]’ will be appended to the excerpt. If the string is less than 55 words, then the content will be returned as is. The 55 word limit can be modified by plugins/themes using the ‘excerpt_length’ filter The ‘ […]’ string can be modified by plugins/themes using the ‘excerpt_more’ filter
<?php wp_trim_excerpt($text, $post); ?>
$text
String
(Optional) The excerpt. If set to empty, an excerpt is generated.
$post
WP_Post•object•int
(Optional) WP_Post instance or Post ID/object. Default is null.
Get The Content get_the_content();
Retrieve the post content.
<?php get_the_content($url, $more_link_text , $strip_teaser, $post; ?>
$more_link_text
String
(Optional) Content for when there is more text.
$strip_teaser
bool
(Optional) Strip teaser content before the more text. Default is false.
$post
WP_Post•object•int • Default value: null
Optional) WP_Post instance or Post ID/object.
Get Dirsize get_dirsize();
A helper function that is used primarily to check whether a blog has exceeded its allowed upload space.
<?php get_dirsize($url, $directory , $max_execution_time; ?>
$directory
String
(Required) Full path of a directory
$max_execution_time
int
(Optional) Maximum time to run before giving up. In seconds. The timeout is global and is measured from the moment WordPress started to load.
Recurse Dirsize recurse_dirsize();
Used by get_dirsize() to get a directory’s size when it contains other directories.
<?php recurse_dirsize($directory, $exclude , $max_execution_time; ?>
$directory
String
(Required) Full path of a directory
$exclude
string • array
(Optional) Full path of a subdirectory to exclude from the total, or array of paths. Expected without trailing slash(es).
$max_execution_time
int • Default Value: null
(Optional) Maximum time to run before giving up. In seconds. The timeout is global and is measured from the moment WordPress started to load.