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:
So each time you change your theme name or copy codes to another theme, changing URLs won’t be necessary.
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.
written by Mehdi Nazari about in WordPress
What do you think about "How to get the Current Theme URL in WordPress"?