WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Implementing HTML code in WordPress PHP (17 posts)

  1. MindstateNL
    Member
    Posted 3 years ago #

    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?

  2. MindstateNL
    Member
    Posted 3 years ago #

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

    http://pastebin.com/sQNiUFZR

  3. esmi
    Forum Moderator
    Posted 3 years ago #

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

  4. MindstateNL
    Member
    Posted 3 years ago #

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

  5. esmi
    Forum Moderator
    Posted 3 years ago #

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

  6. MindstateNL
    Member
    Posted 3 years ago #

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

  7. esmi
    Forum Moderator
    Posted 3 years ago #

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

  8. MindstateNL
    Member
    Posted 3 years ago #

    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?

  9. esmi
    Forum Moderator
    Posted 3 years ago #

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

  10. MindstateNL
    Member
    Posted 3 years ago #

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

  11. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  12. MindstateNL
    Member
    Posted 3 years ago #

    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!

  13. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  14. MindstateNL
    Member
    Posted 3 years ago #

    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

  15. esmi
    Forum Moderator
    Posted 3 years ago #

    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.

  16. MindstateNL
    Member
    Posted 3 years ago #

    Thanks a lot for your help!

  17. esmi
    Forum Moderator
    Posted 3 years ago #

    No problem. :-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.