How To Link Theme Directories?

209. How to link Theme Directories

In this article I’ll tell you some things about linking theme directories and dynamic linking in templates.

So, to link to the theme’s directories, you may use the following functions:

get_template_directory_uri();
get_stylesheet_directory_uri();

If you are not using a child theme both of these functions will return the one and the same thing – the full URI to your theme’s main folder. You may use this to reference sub-folders in your theme like this:

echo get_template_directory_uri() . '/images/logo.png';

If you are using a child theme

 get_stylesheet_directory_uri() will return the URI of your child theme, while get_template_directory_uri() will return the URI of your parent theme. This is especially important to keep in mind when distributing a theme or in any other case where a child theme may or may not be active.

Despite of your permalink settings, you may link to a page or post dynamically by referring to its unique numerical ID with<a href="<?php echo get_permalink(ID); ?>">This is a link</a> .

This is an easy way to create page menus as you can later change page slugs without breaking links, as IDs will stay the same. However, this might increase database queries.

Dynamic page menus may also be created by utilizing Template_Tags/wp_list_pageschild_of parameter or some of the many available plugins.

This much, guys! Hope this article was helpful for you!

Share this!

Post Author: Staff

Leave a Reply

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