Open In App

What are the template tags in WordPress ?

Last Updated : 06 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

WordPress is a free and open-source content management system written in PHP language that allows you to contribute to your project, and host websites all over the world at zero cost. WordPress provides different tags and templates to the user to make their project unique and outstanding.

Template tags in WordPress are nothing but a simple PHP function that is used to present data and customize their blog.

Syntax: The template tag is a PHP function. so it must contain <? and ?> brace within its tag . and must end with a semicolon.

<? 
  php_tag template_tag;
?>

Use:

<? 
  PHP bloginfo();
?>
The blog info template tag displays the information of the current blog.

Properties:

  1. Useful to print dynamic content
  2. PHP function so it’s secure 
  3. Can handle multiple themes and files
  4. Divide code into smaller part 
  5. Easy to understand.
  6. Useful to fetch data from the database.
  7. It can call another theme file within the database.
  8. Can display data by passing argument.

Template Tags: Template tags files are defined in the wp-includes directory.

Extension: " -template.php"

There are a total of 9 template tags in the wp-includes directory: The following is a list of template tag files that can be used in WordPress.

  1. wp-includes/general-template.php
  2. wp-includes/author-template.php
  3. wp-includes/bookmark-template.php
  4. wp-includes/category-template.php
  5. wp-includes/comment-template.php
  6. wp-includes/link-template.php
  7. wp-includes/post-template.php
  8. wp-includes/post-thumbnail-template.php
  9. wp-includes/nav-menu-template.php

Template Tag List: It contains a total of 9 template tags and these are the following:

  1. General tags
  2. Author tags
  3. Bookmark tags
  4. Category tags
  5. Comment tags
  6. Link tags
  7. Post tags
  8. Post Thumbnail tags
  9. Navigation Menu tags

1. General tag: These are defined in the “wp-includes/general-template.php” directory. This General tag contains a total of 29 template tags. These are the following:

Template tag   Description
get_header()  Get header template of current blog
get_bloginfo()  Get information about the current blog site.
get_footer()  Get footer template of current blog.
get_sidebar()  Get sidebar template of current blog.
get_search_form()  Display search form on screen.
wp_loginout()   Display the Log In and log out form .
wp_logout_url()   Get logout URL of current blog
wp_login_form()  Display login form . 
wp_lostpassword_url()   Return password with URL link
wp_title() Display page title in all page of blog.
bloginfo()  Displays information about the current blog site

2. Author tag: These are the different author tags defined in “wp-includes/author-template.php”. Some of the following:

Template Tag  Description
get_the_author()  Get the author name of the current blog
the_author_meta()   Displays a meta data of user.
the_author()  Display  author of the current blog.
the_author_link()   Display author’s data link.
get_the_author_link()   Display Author data URL link.
the_author_posts()   Display the all post count of  author
the_author_posts_link()   Displays link to the author page.

3. Bookmark tags: These are the only 4 template tags of Bookmark tags that are defined in “wp-includes/bookmark-template.php”.

Template Tag  Description
wp_list_bookmarks()   Display all of the bookmarks page
get_bookmark()  fetch Bookmark data
get_bookmark_field()  display single bookmark data
get_bookmarks() . Display  the list of bookmarks pages

4. Category tags:

Template Tag  Description
wp_list_categories()  Displays the HTML list of categories
tag_description()  Display tag description 
the_tags()  Displays the tags of post
wp_generate_tag_cloud()  Generates a tag cloud from provided data
single_term_title()  Display page title
category_description()  Display category description
the_category_rss()  Display the post categories in the feed
the_category()  Displays category list for a post.
wp_dropdown_categories()  Displays the HTML dropdown list of categories
term_description() Display term description.
wp_tag_cloud()  Displays a tag cloud.

5. Comment tags: These are the different comment tag template tags defined in “wp-includes/comment-template.php”. Some of these are the following 

Template Tag  Description
cancel_comment_reply_link()  Displays HTML data for canceled comment reply by admin. 
comment_author_email_link()  Displays the HTML data of email link of author’s current comment
comment_author_rss()  Display the current comment of author .
comment_author_link() Displays the HTML link to the URL of the author’s  comment
comment_author_IP()  Displays the IP address of author comment.

6. Link tags: These are the different template tags defined in “wp-includes/link-template.php”.

Template Tag  Description
get_permalink()  Get permalink for the current post  
get_page_link() Display the permalink of post .
get_admin_url() Display URL of admin.
get_home_url() Display Home Page URL
get_admin_url() Display URL of admin page .
the_permalink()  Displays the permalink for the current post

7. Post tags: These are the different template tags defined in “wp-includes/post-template.php”

Template Tag  Description
next_image_link()  Displays image link of next post . 
post_class()  Displays the class of post.
next_posts_link()  Displays the next posts link
body_class()  Displays the class name of body .

8. Post Thumbnail tags: These are only 4 template tags that are defined in “wp-includes/post-thumbnail-template.php”.

Template Tag  Description
get_post_thumbnail_id()  get thumbnail ID
get_the_post_thumbnail()  Get the post thumbnail
the_post_thumbnail()  Display the thumbnail
has_post_thumbnail()  check whether a post has an thumbnail or not

9. Navigation Menu tags: These are the only 2 template tags defined in “wp-includes/nav-menu-template.php”.

Template Tag  Description
walk_nav_menu_tree()  display the HTML data list for navigation of  menu items
wp_nav_menu()  Displays a navigation menu of current blog


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads