• Resolved MindstateNL

    (@mindstatenl)


    Hi,

    It’s my first time trying to make a WordPress theme from scratch, therefore I chose to first make a site in HTML/CSS and then code that into a WordPress theme.

    Though, I’m having difficulties in implementing IMAGES in my theme. I started with the header.php and I have the following code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    As you may see, there is quite some HTML in there. I was always under the impression that I could use this in my file, but it’s not working for me. It could be really simple, but I couldn’t find it. Someone here who can help me out?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter MindstateNL

    (@mindstatenl)

    I can’t edit my post, but this is the pastebin; sorry forgot that I had to do that here:

    https://pastebin.com/sQNiUFZR

    Ensure that you always use full (absolute) urls for your images.

    Thread Starter MindstateNL

    (@mindstatenl)

    That’s a difference with the HTML code then, right?

    And what if you’re doing it offline, or do I do then (../images/link.jpg) ?

    Ensure that you always use full (absolute) urls for all of your images all of the time.

    Thread Starter MindstateNL

    (@mindstatenl)

    It may be my lack of the knowledge of English language, but what are you referring to here?

    <a href="#"><img src="https://example.com/full_path_to/images/dutch.jpg"></a>

    Thread Starter MindstateNL

    (@mindstatenl)

    Thanks for your response, but what if you are coding offline and you do not yet know how the URL’s are going to be?

    And why does it need to be absolute urls? I have always worked with relative and had no problems, or is this WP specific?

    Use WordPress functions such as <?php echo home_url( '/' ); ?> or <?php echo get_stylesheet_directory_uri(); ?>. and, yes, this is WordPress specific.

    Thread Starter MindstateNL

    (@mindstatenl)

    Thanks a bunch!

    I’m aware of that I’m not using functions there, but for example I want to include my logo like this:
    https://i54.tinypic.com/303ijc8.png

    Would I need to make use of functions too? And if so, how would I do that since I just want to implement the image?

    If you want the theme to be portable, then don’t hard code the first part of the url – use WP functions instead. If you’re adding your logo image to the header.php markup/code, then you’ll need to use the appropriate function there too. The Twenty Ten theme includes an example of this in its header.php template file.

    Thread Starter MindstateNL

    (@mindstatenl)

    The theme is just for one specific site, I’m not planning to use it anywhere else, so hard-coded would be fine then?

    Because then my basic question would remain, I understand that I would then have to change:

    <div id="logo">
    <a href="#"><img src="images/logo.jpg"></a></div>

    to

    <div id="logo">
    <a href="#"><img src="hard-coded url here"></a></div>

    [Please post code snippets between backticks or use the code button.]

    And i would be fine? And how does one create a hard-code when he’s working local?

    Thanks!

    I’m not planning to use it anywhere else, so hard-coded would be fine then?

    Not if you plan to develop it on one server and then upload it to another. Use WP functions.

    Thread Starter MindstateNL

    (@mindstatenl)

    Thanks. I think I understand now, so basically for every image that I want to be implemented on the site, even if I don’t want it to ever change and always stay like it; I need to use a ‘function’? For example the logo

    Yes! This ensures that your theme is fully portable and can be moved from a development server to a live one. It’s also good WP coding practice.

    Thread Starter MindstateNL

    (@mindstatenl)

    Thanks a lot for your help!

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Implementing HTML code in WordPress PHP’ is closed to new replies.