Support » Themes and Templates » Relative theme path in a tag

  • gesikah

    (@gesikah)


    I am working on a theme for my new WP website and I am a bit rusty at it and have run into a problem.

    I want to use or add images for some of the postmetadata (‘edit post’ and comments links), but I would rather not use an absolute path (http://www.url.com/wp-content/themes/themename/images/image.jpg) unless absolutely necessary.

    Is there some way of calling the theme directory path inside of a template tag? A variable that I can use with the edit_post_link() function? So I would end up with something like:

    <?php edit_post_link('<img src="<insert theme path>/images/edit.jpg" />', '', ' | '); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • moshu

    (@moshu)

    The stylesheet_directory is supposed to do that (despite what it says about being deprecated).
    However, since you cannot place directly a tag into a tag… you will need to modify it.

    Thread Starter gesikah

    (@gesikah)

    Any suggestions about the best way to go about it? Or best place to start?

    Thread Starter gesikah

    (@gesikah)

    For future reference and anyone else that might be wondering this works like a charm.

    <?php edit_post_link('<img src="' . get_bloginfo('stylesheet_directory') . '/images/edit.jpg" />', '', ' | '); ?>

    I knew there was a reason I kept him around, even if he doesn’t put the empty milk jug in the garbage.

    Just thought I’d post a follow up here to let everyone know that stylesheet_directory was deprecated as of WP 2.3.1

    If you need to reference the theme directory you can now use this:
    <?php bloginfo('template_directory'); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Relative theme path in a tag’ is closed to new replies.