Understanding Template Tags and how they work

understanding template tags and how they work
Share this:
Share

Template Tags

PHP functions utilized as a part of your WordPress theme templates  to show Loop content are called template tags. These tags are utilized to show particular bits of information about your site and content. This permits you to customize how and where content is shown on your site.

For instance, the the_title() template tag shows the title of your post or page inside the Loop. The significant advantage of utilizing template tags is that you don’t have to know PHP code to utilize them.

Various template tags are accessible in WordPress. Some template tags must be inside the Loop, while different tags can be utilized anyplace as a part of your theme template files. Take note of that in this specific circumstance, template tags allude to the WordPress capacities used to concentrate post information for show; template files are the topic components that control how content for a specific content type is shown.

Put another way, template files contain Loops including template tags. For an upgraded rundown of template tags accessible in WordPress visit http://codex.wordpress.org/Template_Tags.

Ordinarily Used Template Tags

There is no deficiency of template tags, however ordinarily you will utilize just a modest bunch of tags in your Loops.

Taking after are the most ordinarily utilized template tags accessible as a part of the Loop. These template tags will return and show the post information recorded.

➤ the_ permalink(): Returns the URL of your post.

➤ the_title(): Returns the title of the post.

➤ the_ID(): Returns the one of a kind ID of your post.

➤ the_content(): Returns the full content of your post.

➤ the_excerpt(): Returns only an extract of your post. In the event that the Excerpt field is rounded out on the

Post edit screen, that will be utilized. If not WordPress will auto-create a short selection from your post content.

➤ the_time(): Returns the date/time your post was published.

➤ the_author(): Returns the author of the post.

➤ the_tags(): Returns the tags attached to the post.

➤ the_category(): Returns the classifications doled out to the post.

➤ edit_ post_link(): Displays an “”edit”” interface that is indicated just in the event that you are logged in and permitted to edit the post.

➤ comments_ popup_link(): Displays a connection to the comments form of your post.

To figure out how template tags function, simply put any template tag inside the Loop and view the outcomes. The taking after case sees the estimations of a couple distinctive template tags:

As should be obvious your post titles are shown with connections to the permalink for every post. The content of the post is shown straightforwardly underneath the post title.

Tag Parameters

Most template tags have parameters that can be added to alter the value returned. For instance, the the_content() template has three parameters. The principal parameter permits you to set the “”more”” link content like so:

Your post content will be shown as typical, yet when the <!- – more- – > tag is found in your post, WordPress will naturally include the content ”Read more,” which would connection to the whole blog entry. The second parameter figures out if to show the teaser paragraph again when seeing the full post.

The default value is False so the teaser will be shown in both places.

The More tag in WordPress permits you to show a characterized mystery from the full post on your site. For instance, you could show the principal passage of a post on your homepage, and just demonstrate the full blog entry when a guest taps the connection to see the full post. To fulfill this you can put <!- – more- – > in your substance in HTML see where you need this break to happen. In the visual editorial manager there is a catch to embed a More tag.

You can likewise send numerous parameters to any tag that backings it. For instance, the template tag the_title() acknowledges three parameters: $before, $after, and $echo. The accompanying code sets the the_title() label’s $before and $after parameters to wrap the post title with h1 labels:

You can likewise see the real capacity in the WordPress source code. The post layout capacities are situated in wp-incorporates/post-template.php. Doing a brisk hunt down ”capacity the_title()” will lead you to the correct capacity for the the_title() tag. You can likewise utilize the Codex for a nitty gritty depiction of the layout label you are working with, for this situation

http://codex.wordpress.org/Template_Tags/the_title.

What are your thoughts about this post? Let me know in the comments!

Did you like this article about various WordPress Template Tags? Share it with your friends on Facebook, Twitter, and Google Plus!

Don’t forget to Subscribe to our Newsletter for more insightful post updates, tips and guides!

See you in the next post.

Stay awesome!

Authored By Aakanksha

Hi, I’m Aakanksha, a computer science engineer and the founder of TheTechPower. I help people make there online presence process easier by empowering them with clean, beautiful and easy to use wordpress themes.

Share this:
Share

2 Comment

  1. Hey Aakanksha,

    It’s good to meet another WordPress developer.

    WordPress themes are basically developed of these tags. The more you learn about WordPress tags, functions, hooks, more you will have the expertise.

    For every single part of the theme, you have to use the functions and the tags mentioned above.

    WordPress comes with the bundle.
    An informative post indeed.
    ~Ravi

    1. Aakanksha says: Reply

      Indeed, tags are the integral part of any theme. Nice to meet you too.
      Thanks for the comment.

Leave a Reply