• Hello everyone. Ive been exploring and playing around with wordpress the past day and at the moment Im trying to modify the header file so I can put my own image directly into the header (not through the stylesheet). Now I have no problem with the coding and everything but one thing that eludes me is what do I specify the path as? I realize that the header.php file is simply being included into every page but how can I navigate to my images directory? I assumed that I could use the same path that I used in my stylesheet but that doesn’t work.

    If someone can shine some light on the issue Id appreciate it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • In the stylesheet, it is likely using relative links. If you are going to add images to your header with HTML, you might have better luck using absolute links.

    Check out the Designing Headers article for lots of good info on tweaking your header.

    Thread Starter iamchel

    (@iamchel)

    Is it possible to use relative links? I was under the impression that using absolute links is generally poor practice.

    Sure, you can use relative links. Where have you uploaded your images? Via WordPress into the default upload directory? That’s under wp-content/uploads. In that case you should be happy with something like this:

    <img src=”/wp-content/uploads/my_header_image.jpg” />

    In case you haven’t installed WordPress in the root directory of your website but, say, under wordpress or blog you’ll have to change the path above to match this, e.g. /blog/wp-content/....

    Anyway I’d go with Josh’s recommendation and use absolute links. You don’t have to hardcode them into the theme but just use some PHP. You can read about that here and there; have a look at the parameter template_directory. Looking at get_option('upload_path') might be interesting as well as it returns something like this https://example.com/wp-content/uploads/.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Accessing images in header.php’ is closed to new replies.