markjaquith / feedback

Ask @markjaquith anything!
42 stars 4 forks source link

Code Snippets to Correct Doubling of WordPress Featured Images ? #17

Closed Shapeshifter3 closed 10 years ago

Shapeshifter3 commented 10 years ago

Mr. Jaquith,

Several (or more) of Automattic's WordPress Themes place the Featured Image of Blog Posts (formatted as "Standard") at the top of the post itself when the image is clicked as a link to the post.

Is there any Code Snippet(s) that I can use to insert into any theme that displays this problem?

MickeyKay commented 10 years ago

Is there a theme, or themes, in particular that you're referring to? Most well-built themes will output components like a featured image using a hook, which means that you can easily modify/remove those components with a proper call to remove_action or remove_filter. Sometimes it takes some sleuthing to find the right hook, but I'll usually just run a search across all theme files for a bit of the html in a component (e.g. class="featured-image" or even just featured-image) to see where it's being spit out.

Shapeshifter3 commented 10 years ago

I found this issue in both Twenty Thirteen, and Sorbet.

MickeyKay commented 10 years ago

Gotcha, thanks. Well, digging into Twenty Thirteen, it looks like I was wrong - no hook. Looking in content.php, here's the code for the thumbnail:

<div class="entry-thumbnail">
    <?php the_post_thumbnail(); ?>
</div>

So it looks like your options are a bit more limited.

  1. Override content.php with your own version of the file - if you do this, make sure to create a child them so your changes aren't overwritten if you update.
  2. If you're looking for more of a snippet approach, then just add the following CSS (either using a CSS plugin, or by enqueueing your own CSS file:
.entry-thumbnail {
    display: none;
}

Sorry to not be more helpful. Mark or someone else might come along with a much better solution, but this is how I'd do it. Good luck!

markjaquith commented 10 years ago

@MickeyKay's suggestions are good, in the case that the theme has hardcoded this function into one of their templates. Do note that hiding it with CSS won't stop it from loading, so it's a bit of a bummer from an efficiency standpoint. Just creating a child them is a good idea anyway.