How do I get the theme URL in PHP?

  • I need to get the URL of my theme directory to reference an image in the theme's image/headers directory. How is this done in PHP?

  • EAMann

    EAMann Correct answer

    10 years ago

    This function will return the theme directory URL so you can use it in other functions:

    get_bloginfo('template_directory');
    

    Alternatively, this function will echo the theme directory URL to the browser:

    bloginfo('template_directory');
    

    So an example for an image in the themes images/headers folder would be:

    <img src="<?php bloginfo('template_directory'); ?>/images/headers/image.jpg" />
    

    NOTE: this will give you the path to the *parent* theme if you are currently using a child theme, and not the active child theme. A longer answer below explains this in more detail.

    You can simply use `get_template_directory_uri()`

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM