Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

GianLuca D'Intino-Conte
GianLuca D'Intino-Conte
2,134 Points

Remove Featured Image Link

I've been working on Wordpress a lot lately and have been able to cross most of the hurdles I've encountered using the codex.

But I have not been able to deactivate the links on featured images from posts.

I want to be able to selectively disable a featured image's link to the full post.

Any insight would be greatly appreciated!

1 Answer

Andrew McCormick
Andrew McCormick
17,730 Points

Since this can be theme dependent, can we have a little more info?

What theme are you using?

Is this for the page where you list your most recent blog entries, archives page, category page, single page?

Is there a template file related to that page already in place? Follow the Hierarchy template hierarchy

Typically you are looking at something like this:

<?php if ( has_post_thumbnail()) : ?>
   <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
   <?php the_post_thumbnail(); ?>
   </a>
 <?php endif; ?>

to remove the link it would look like this

<?php if ( has_post_thumbnail()) : ?>
 //remove opening a tag
   <?php the_post_thumbnail(); ?>
//remove closing a tag
 <?php endif; ?>

hope that helps.

GianLuca D'Intino-Conte
GianLuca D'Intino-Conte
2,134 Points

Thanks for the really quick reply,

I'm using a theme called DynamiX

It's for the home page which can currently be seen at http://scanpro.developpement360.ca/

The template file for that page is the "default page" one under this theme.

If I were to remove all the links from all the featured images, could I do that with a "global function" from the functions.php file?

Andrew McCormick
Andrew McCormick
17,730 Points

hmm... it's according to how that them is setup. The function the_post_thumbnial()` in itself does not add a link. So if the theme has added a filter, then you might be able to remove that filter.

try looking for a filter with "post_thumbnail_html' see Codex on the_post_thumbnail