• Hi all,

    I have a need to reference my post’s featured thumbnail. I was able to display it no problem with the use of

    <?php the_post_thumbnail(); ?>

    However I notice it links to the actual post it came from, is it possible to have it just reference the img src itself and now auto attach a link to itself? Thanks in advance.

Viewing 8 replies - 1 through 8 (of 8 total)
  • By default, the_post_thumbnail() doesn’t create a link to anything. It just displays the image & nothing more. Perhaps the answer lies in the surrounding code?

    Thread Starter Kevin Kwok

    (@queesy)

    Hmm dont think so, unless the query_posts is attaching a link somehow. Here’s my code

    <?php query_posts('category_name=cloud&showposts=100&orderby=title&order=asc');
    while ( have_posts() ) : the_post();
    echo '<li>';
    the_post_thumbnail();
    echo '<a class="fancybox" href="#';
    the_title();
    echo '">';
    the_title();
    echo '</a><div id="';
    the_title();
    echo '" style="width:200px; line-height:18px; display:none;"><p><h2>';
    the_title();
    echo '</h2>';
    the_content();
    echo '</p></div></li>';
    endwhile;wp_reset_query();
    ?>

    what is the html output of the full web page (‘view source’ in your browser)?

    does the web page validate?
    validator.w3.org
    http://codex.wordpress.org/Validating_a_Website

    Thread Starter Kevin Kwok

    (@queesy)

    Here is the html output

    <li>
    <a href="http://www.kevinkwok.com/dev8/maginatics/" title="Maginatics">
    <img width="125" height="125" src="/wp-content/uploads/2013/10/logo.png" class="attachment-post-thumbnail wp-post-image" alt="logo"></a><a class="fancybox" href="#Compan">Company</a><div id="Compan" style="width: 200px; line-height: 18px; display: none;"><p></p><h2>Company</h2><div>(1) Company name</div>
    <div><p>Content here</p></div></li>

    does that also happen if you temporarily deactivate all plugins?

    Thread Starter Kevin Kwok

    (@queesy)

    tried deactivating every plugin still happening! =( anyone know of a fix?

    Thread Starter Kevin Kwok

    (@queesy)

    Could it be the

    while ( have_posts() ) : the_post();

    part of the code?

    Moderator bcworkz

    (@bcworkz)

    Possible but highly unlikely, it must be your theme adding the link, because as esmi pointed out, the function does not normally do this. Probably the best approach is to identify how your theme is adding this link, probably by hooking into one or more of the several ‘*thumbnail_html*’ filters where * in this case means other text may occur before or after the main text. If you can identify how the filter was added, you can remove it again from a child theme.

    Added filter hooks would most likely be accomplished in functions.php. If for some odd reason the link was added in the loop as you suggest, the code doing that would be evident in the template files.

    Failing that, use get_the_post_thumbnail() instead, and extract the <img> tag from the returned HTML using PHP string manipulation functions. Echo out only that tag without the link portion.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Reference post thumbnial without it linking to post’ is closed to new replies.