How to get media attachment url without any link in WordPress

I have following code to get all media attachment associated with any category:

<?php
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
    setup_postdata($post);
?>
<li class='element <?php the_category($post->ID); ?>'>
              <div class="portfolio-image">
                <a href="#">
                  <?php  echo '<img class="attachment-portfolio-four wp-post-image" src="'.the_attachment_link($post->ID,false).'" height="200" width="235">'; ?>
                </a>

                <div class="mask">
                  <div class="links">
            <a data-gal="prettyPhoto[portfolios]" href="<?php the_attachment_link($post->ID); ?>"><i class="icon-resize"></i></a>
                      <a href="#">
                        <i class="icon-link"></i>
                      </a>
                  </div>
                </div>
              </div>

            </li>
<?php    } }        ?>

But line

Read More
<?php  echo '<img class="attachment-portfolio-four wp-post-image" src="'.the_attachment_link($post->ID,false).'" height="200" width="235">'; ?>

giving following output in HTML

<a href='http://koncept.org.in/wp-content/uploads/2016/02/vishal.jpg'><img width="150" height="150" src="http://koncept.org.in/wp-content/uploads/2016/02/vishal-150x150.jpg" class="attachment-thumbnail size-thumbnail" alt="vishal" /></a><img class="attachment-portfolio-four wp-post-image" src="" height="200" width="235"></a>

I want only media attachment url so i can use as i want. Can anybody help me out here?

Related posts

1 comment

  1. This should work

    Change

    .the_attachment_link($post->ID,false).
    

    To

    .wp_get_attachment_url( $post->ID, true ).
    

Comments are closed.