www.webdeveloper.com
Results 1 to 2 of 2

Thread: Adding image to variable

Hybrid View

  1. #1
    Join Date
    Jun 2014
    Posts
    1

    Adding image to variable

    Hi there

    I am a novice with regards to PHP, and i am trying something simple, but i am not sure why it will nto work.

    I basically just want to assign an image to a variable, and the display it. I have created the following code, but it just displays the text and does not recognise its a path to the image file.

    Im sure i have to add som HTML in here some where but i don't know what! Please could someone show me what code i need to write in order to make this work?

    I am using wordpress, and i am currently using a hook. This code displays the words, but i need it to display the image.

    <?php
    add_action( 'woo_header_inside', 'woo_add_image' );
    function woo_add_image () {
    $content = 'http://www.mywebsite.com/images/myimage.jpg';
    echo $content;
    }
    ?>

    Thanks very much

  2. #2
    Join Date
    Mar 2012
    Posts
    1,740
    What you want to do is make the code displaying an image variable. You have no code to display an image, so none are going to be displayed, variable or otherwise. E.g. The code:

    <img href="path/image.jpg" alt="description">

    will display the image called "image.jpg". Whereas the code:

    <?php
    $image='name';
    echo '<img href="path/'.$image.'.jpg" alt="description">';
    ?>


    will display the image whose name is stored in the variable $image.

    That is the basics, but I have no idea how you implement that into a WordPress site...
    Last edited by jedaisoul; 06-21-2014 at 04:38 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles