Author - StudySection Post Views - 40 views
wordpress template

WordPress Template Tags

Introduction

Template tags are basically working as functions. It is a PHP function used to generate and display information dynamically. We can use them to customize the WordPress site. WordPress Themes contain different templates and themes and we can use template tags to fetch and display dynamic data. WordPress has many built-in template tags that will be utilized in WordPress themes. WordPress plugins and themes also can define their own template tags and use them in numerous templates.

How to use

The function should be defined in the theme’s functions.php file later we can use that theme function as a template tag. We can also pass parameters in template tags. These tags files are stored in the wp-includes directory. Here is the example below, we have defined a function that displays some text.

Example:
<?php function show_text() {
$this_article = wp_title('',true);
echo '<p>Hi, if you enjoyed reading '.$this_article.' please consider <a href="http://www.example.com/">here</a>.';
} ?>

To use this function in a template, add this line of code:
<?php show_text(); ?>

Types of Template Tags

There are different types of template tags that we can use to display data in templates. We can use these templates to show the title, content, author, name, etc. Here are the types of templates tags:

  1. General tags: General tags are those tags used to general-purpose like to display the header, footer, sidebar, of website and to show Title, name, content, etc. of post or page. These tags are defined in general-template.php. We can also do customizations in these functions according to our requirements. Here is the list of some general tags.

    1. get_header()
    2. get_footer()
    3. get_sidebar()
    4. bloginfo()
    5. get_template_part()
    6. wp_enqueue_script()
  2. Author tags: Author tags are used to show the author’s info like the author name, author’s posts, the author’s meta information, etc. These tags are defined in author-template.php. Here is the list of some author tags.

    1. wp_list_authors()
    2. the_author()
    3. get_the_author()
    4. the_author_posts()
    5. the_author_meta()
  3. Bookmarks tags: A Web bookmark is a link on a page pointing to another area within the same page. Bookmarks also may direct site visitors back to the up with an appropriately named “back to top” link, sending them to the main list of links at the start. We can also use bookmarks according to our requirements by using bookmark tags. Here is the list of bookmark tags.

    1. wp_list_bookmarks()
    2. get_bookmark()
    3. get_bookmark_feild()
    4. get_bookmarks()
  4. Category tags: Categories, tags, and taxonomies are all related and can be easily confused. To maintain and use all of these we use the category tags.There are many defined category tags and we create our custom category tags. Here is the list of some category tags.

    1. the_category()
    2. wp_list_categories()
    3. the_terms()
    4. the_taxonomies()
    5. the_tags()
  5. Comment tags:Comments tags contain all types of comments functions. The comments.php template contains all the functions needed to get comments from the database and show them in your theme. Here is the list of some comment tags.

    1. comment_author()
    2. comment_date()
    3. comment_excerpt()
    4. comment_form()
    5. comment_time()
  6. Link Tags: Whether you use permalinks or not, in templates we can link to pages or posts dynamically by referring to its unique numerical ID with <a href=”<?php echo get_permalink(ID); ?>”>This is a link</a>. By using link tags we can also get the current URL, site URL, home URL, etc. we can also create new links by using link tags. Here is the list of some link tags.

    1. the_permalink()
    2. get_permalink()
    3. home_url()
    4. site_url()
    5. get_admin_url()
  7. Post tags: Post tags are used to display the post data such as title, name, content, date, time, etc. We can also use these tags to customize templates. We can also create custom post tags according to requirements. Here is the list of post tags.

    1. the_content()
    2. the_ID()
    3. the_excerpt()
    4. the_meta()
    5. the_title()
  8. Post Thumbnail tags: These tags are used to show the images of the post or page. By using these tags we can adjust the size of images like thumbnail, medium and large. Here is the list of thumbnail tags.

    1. has_post_thumbnail()
    2. get_post_thumbnail_id()
    3. the_post_thumbnail()
    4. get_the_post_thumbnail()
  9. Navigation Menu tags: Navigation menus are used to display the menu anywhere in the theme. If we want to customize the website you need to create custom menus then you can use these tags. Here is the list of navigation menu tags.

    1. wp_nav_menu()
    2. register_nav_menu()
    3. register_nav_menus()
    4. unregister_nav_menu()
    5. has_nav_menu()
  10. Conditional tags: Conditional Tags can be used in Template files to change which content is displayed and how that content is displayed on a particular page depending on what conditions that page matches. For example, you might want to display a snippet of text above the series of posts, but only on the main page of your blog. By using Conditional Tags, that task is made easy. It always returns a boolean value. All the Conditional Tags test to see whether a certain condition is met and then returns either TRUE or FALSE. Here is the list of some conditional tags.

    1. is_home()
    2. is_front_page()
    3. is_admin()
    4. is_single()
    5. is_page()

If you have skills in PHP programming and you want to enhance your career in this field, a PHP certification from StudySection can help you reach your desired goals. Both beginner level and expert level PHP Certification Exams are offered by StudySection along with other programming certification exams.

Leave a Reply

Your email address will not be published. Required fields are marked *