• I’m working on a theme index.php file and it seems that when I use the “template_directory” it is not actually pulling the url path of the file, but instead is just pulling the main domain name. So instead of

    https://example.com/wp-content/themes/theme_name/images/pic.jpg

    its pulling the domain url and showing this

    https://example.com/images/pic.jpg

    I don’t understand why it’s doing this, since the index.php file is actually in the right directory. (which is inside the theme folder). There is the index.php file that is in the wordpress directory… but I don’t understand why it would conflict with the themes index.php file.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Is your theme a child theme? If so, try something like:

    <img src="<?php bloginfo('stylesheet_directory'); ?>/images/pic.jpg" alt="your alternative text" width="nnn" height="mmm" />

    (bloginfo() reference)

    HTH

    PAE

    when I use the “template_directory”

    what is the exact code you are using?

    Thread Starter JoshuaHowell

    (@joshuahowell)

    This is the code I WAS using

    <?php bloginfo(‘template_directory’); ?>

    but, upon more research, i’ve found that that code does not work too well, so I use this now:

    <?php echo get_template_directory_uri(); ?>

    and it works like a charm.

    What I really need is a better tutorial that was made with wordpress 3.0. The one i’m using was created in 2009 and alot of the code used in the tutorial simply doesn’t work.

    your original code had ‘squint’ single quotes which often come from copy/paste from some articles –
    they have to be ‘straight’ single qouotes;

    this might have worked:
    <?php bloginfo('template_directory'); ?>

    Thread Starter JoshuaHowell

    (@joshuahowell)

    You hit the nail on the head alchymyth. It was my stupidity (once again). Thanks, you just saved me from myself.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Template Tag “template_directory” pulling wrong path’ is closed to new replies.