WordPress.org

Ready to get started?Download WordPress

Forums

Post/Page Image Src HTML not Visual (11 posts)

  1. jeremi_liwanag
    Member
    Posted 1 year ago #

    Hi,

    I want to use the <img src="images/image1.jpg /> code on my wordpress pages.

    not in backend but inside the "html wordpress post page" ( the one where you write the articles).

    because if it's backend it will be like this right?

    <img src="<?php bloginfo('template_directory'); ?>/images/image1.jpg />

    I dont want to upload the images,(because they are already in my images folder). i want to get it directly in my images folder (no upload media stuff)

    because if i upload it, the src will be like this

    http://localhost/wordpress/wp-content/uploads/2012/10/image1.jpg

    is there any shortcut for this one?
    because i'm trying to upload hundreds of tiny images, and i already have my html code setup

    if i can just copy paste it into the "html publish page" that will be great!

    Thanks,
    Jeremi L.

  2. Andrew Nevins
    Barrel rider & Volunteer Moderator
    Posted 1 year ago #

    Have you access to the directories of your website?

  3. jeremi_liwanag
    Member
    Posted 1 year ago #

    What do you mean access? I'm using WordPress locally for now. I'm using WAMP

  4. Andrew Nevins
    Barrel rider & Volunteer Moderator
    Posted 1 year ago #

    Can you create a directory within your theme, name it relevantly and put all your images in there? Then you can specify that directory in your URLs.

  5. jeremi_liwanag
    Member
    Posted 1 year ago #

    Yes, i think i already have created a folder inside my theme

    WordPress/wp-content/themes/myTheme/images/ (this is where my images at)

    So the img src will be like

    <img src="images/image1.jpg" /> right? but this one doesn't work

  6. Andrew Nevins
    Barrel rider & Volunteer Moderator
    Posted 1 year ago #

    Try
    /wp-content/themes/yourThemeName/images/image1.jpg

  7. jeremi_liwanag
    Member
    Posted 1 year ago #

    Tried /wp-content/themes/yourThemeName/images/image1.jpg

    doesn't work :`(

    i wonder if there's a plugin that can do that

    instead of http://localhost/wordpress/wp-content/uploads/2012/10/image1.jpg

    it will accept

    images/image1.jpg

    i really need a help on this ..

    because i have a lot of mini icons that are in unordered list. do i have to upload them and copy paste the url one by one? that will take me at-least a day to complete it.

  8. Andrew Nevins
    Barrel rider & Volunteer Moderator
    Posted 1 year ago #

    Did you try replacing yourThemeName with your actual theme name?

  9. jeremi_liwanag
    Member
    Posted 1 year ago #

    Yes i did,

    actually it's like this

    /wp-content/themes/mysite/images/miniperson.jpg

    also tried this

    wp-content/themes/mysite/images/miniperson.jpg

    /mysite/images/miniperson.jpg

    mysite/images/miniperson.jpg

    /images/miniperson.jpg

    images/miniperson.jpg

    /wordpress/wp-content/uploads/2012/10/image1.jpg

    wordpress/wp-content/uploads/2012/10/image1.jpg

    /wp-content/uploads/2012/10/image1.jpg

    wp-content/uploads/2012/10/image1.jpg

    none of them seems to work

  10. Xaliber
    Member
    Posted 1 year ago #

    I think this might be a bit overkill, but you could try using shortcode.

    Add this to your functions.php:

    // Create the shortcode
    function template_url( $atts, $content = null ) {
        return '<img src="'. get_template_directory_uri() .'/'. $content .'" alt="" />';
    }  
    
    // Add as shortcode
    add_shortcode("template", "template_url");

    To use it, you could simply type this in your WordPress visual editor:
    [template]images/image1.jpg[/template]

    Which would result as:
    <img src="http://yoursite.com/wp-content/themes/yourtheme/images/image1.jpg" alt="" />

    This isn't tested though, so it may contain errors. But the basic should look like that. :)

  11. ojassvi
    Member
    Posted 1 year ago #

    Thanks Xaliber. Great piece of code. It worked out smoothly.

Topic Closed

This topic has been closed to new replies.

About this Topic