0

I want to be able to reference the theme directory in a page/post using php code. I don't know how to do this with WordPress but other CMS use something like a path_to_home php variable like

<img src="<?php path_to_home() . 'images/image.jpb'; ?>">

In WP I tried

<img class="first-slide" src="<?php get_template_directory_uri() . '/images/landing-banner.png'; ?>" alt="First slide">

but that doesn't work the same way or I need something different than get_template_directory_uri().

BTW my output with this code is a literal

<img class="first-slide" src="<?php get_template_directory_uri() . '/images/landing-banner.png'; ?>" alt="First slide">
1
  • 2
    You are missing echo before calling get_template_directory_uri() Sep 22, 2015 at 18:34

2 Answers 2

1

Whenever using any WordPress function with get_xyz_etc() make sure you ECHO the function if you want to output the value there:

<img class="first-slide" src="<?php echo get_template_directory_uri() . '/images/landing-banner.png'; ?>" alt="First slide">

It will now output the path!

1

Like @czerspalace said : you just miss echo

<img class="first-slide" src="<?php echo get_template_directory_uri() . '/images/landing-banner.png'; ?>" alt="First slide">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.