Top 5 Useful WordPress Template Tags

<?php echo get_permalink(00); ?>

It’s good practice to use this code rather than hard coding links. If you hard code links (domain.com/original-path-to-link) then change permalinks for whatever reason (domain.com/new-path-to-link), you have to go back and recode every link manually. Using get_permalink(); is the solution. It keeps track of the Page/Post ID. To find out the id of a Page or Post, hover over the page/post and it should be visible in the status bar. Otherwise edit the page/post and you’ll see it in the url (www.domain.com/wp-admin/post.php?post=000&action=edit).

<?php echo get_category_link('00'); ?>

Same function as get_permalink() for cetegories. Make sure to use apostrophes around the ID. The wordpress codex has a complex method to achieve the same result instead.

<?php bloginfo('url'); ?>

Good to use in anything that links to your homepage such as your Header logo.

Example:
<a href="<?php bloginfo('url'); ?>">Homepage Link</a>

<?php bloginfo('template_directory'); ?>

A great way to link to any images in your template directory.

Example:
<img src="<?php bloginfo('template_directory'); ?>/images/logo.gif" />

<?php if ( is_page_template( 'template-filename.php' ) ) ?>

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.