How to Get the Current Theme URL in WordPress

2 from 5
from 9 user
(Rate this post)
How to Get the Current Theme URL in WordPress

When developing WordPress, retrieving the Current Theme URL is helpful, especially to load file URLs located under the Current Theme directory. WordPress bloginfo() function can retrieve the Current Template URL.

Managing URLs when directory names can be changed is a challenging task to do!

To overcome this issue, a pro WordPress developer must use functions instead of fixed URLs.

For example, if you use this URL when you want to load CSS:

<link type="text/css" href="https://website.com/wp-content/themes/theme-name/css/style.css" rel="stylesheet"/>

You will run into loading problems each time you want to change the name of your theme.

But what if you can get this part of the URL in a parameter:

https://website.com/wp-content/themes/theme-name/

So each time you change your theme name or copy codes to another theme, changing URLs won’t be necessary.

Using the bloginfo('template_directory') in your codes will print the Current Theme Directory for you.

For example, use this code when you want to load a CSS file located inside your current theme directory:

<link type="text/css" href="<?php bloginfo('template_directory'); ?/>/css/style.css" rel="stylesheet"/>

Read more about the bloginfo function on WordPress’s official website.

What do you think about "How to Get the Current Theme URL in WordPress"?

Your rating submit was successfull.

Your rating submit was not successfull.

Menu