Forums

Template Tag “template_directory” pulling wrong path (6 posts)

  1. JoshuaHowell
    Member
    Posted 8 months ago #

    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

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

    its pulling the domain url and showing this

    http://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.

  2. peredur
    Member
    Posted 8 months ago #

    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

  3. alchymyth
    The Sweeper
    Posted 8 months ago #

    when I use the "template_directory"

    what is the exact code you are using?

  4. JoshuaHowell
    Member
    Posted 8 months ago #

    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.

  5. alchymyth
    The Sweeper
    Posted 8 months ago #

    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'); ?>

  6. JoshuaHowell
    Member
    Posted 8 months ago #

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

Reply

You must log in to post.

About this Topic