Support » Fixing WordPress » Implementing HTML code in WordPress PHP

  • 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)
  • I can’t edit my post, but this is the pastebin; sorry forgot that I had to do that here:

    http://pastebin.com/sQNiUFZR

    esmi

    (@esmi)

    Forum Moderator

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

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

    esmi

    (@esmi)

    Forum Moderator

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

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

    esmi

    (@esmi)

    Forum Moderator

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

    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?

    esmi

    (@esmi)

    Forum Moderator

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

    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?

    esmi

    (@esmi)

    Forum Moderator

    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.

    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!

    esmi

    (@esmi)

    Forum Moderator

    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.

    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

    esmi

    (@esmi)

    Forum Moderator

    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.

    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.