Solution 1 :

There are several ways to get an image in WordPress.


1) If you image is the thumbnail image of the page or post, you can simply use echo of get_the_post_thumbnail_url().

<img src="<?php echo get_the_post_thumbnail_url(); ?>" alt="">

2) If your image is in the media library, you can use the function wp_get_attachment_image( $attachment_id, $size, $icon, $attr );. You must know the image ID.

<?php echo wp_get_attachment_image(300, array('800', '600'), "", array("class" => "image")); ?>

300 is the ID of the image in the library (you can discover it looking at the number in the url when opening the image there).
800 and 600 is the size.
An attribute was added: class="image".

By default, it will output this:

<img width="700" height="466" src="example.com/wp-content/uploads/2020/02/image.png" class="image attachment-700x600 size-700x600" alt="" srcset="example.com/wp-content/uploads/2020/02/image.png 800w, example.com/wp-content/uploads/2020/02/image-png-1-300x200.png 300w" sizes="(max-width: 700px) 100vw, 700px">

3) If you want the image from media library as well, but just the url, you can use wp_get_attachment_image_url( $attachment_id ) function. Like this:

<?php echo wp_get_attachment_image_url(1286); ?>

4) If you image is in a custom field, created using the Advanced Custom Fields plugin, for example. Then, you call the_field using like this:

<?php the_field('image_field_name'); ?>

5) If the image is not in the media library, but in the theme folder, you can use the get_stylesheet_directory() to find the theme folder and render the image. For example, if the image is inside the theme folder, inside another folder called img.

<?php echo get_stylesheet_directory().'/img/image.png'; ?>

Problem :

I am converting Html Template to WordPress, I have done 90% of the work.

In my Template, I have some <a> which are href to the images path as

<a href="img/elements/g7.jpg" class="img-pop-up">

Now i want to link this path in wordpress using any funtion,like i have done for img tag as

<img src="<?php bloginfo('template_url'); ?>/img/logo.png" alt="">

May you help me,how can i give the path to image using <a>tag.

Comments

Comment posted by Adnan Khan

no i am not using the child theme

Comment posted by A1Gard

what;s the main problem? tell us clearly.

Comment posted by Adnan Khan

i want to give the path to images which are save in folder, using the a tag,i don’t know how to give them in wordpress.

Comment posted by Stender

Some more examples

By