Skip to content

Instantly share code, notes, and snippets.

@Santel
Last active January 16, 2021 16:49
Show Gist options
  • Save Santel/8451460 to your computer and use it in GitHub Desktop.
Save Santel/8451460 to your computer and use it in GitHub Desktop.
Remove first image from WordPress post
//* Remove first image from single post
function remove_first_image ($content) {
if (!is_page() && !is_feed() && !is_home()){
$content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
} return $content;
}
add_filter('the_content', 'remove_first_image');
@ACEkin
Copy link

ACEkin commented Jan 16, 2021

I chose a reversible course and globally hid the image using CSS. It specifically applies to posts that have been converted to block editor. I added the following to the site custom CSS in Customize.

/* Hide the lead image in a post at the top */
.wp-block-image:first-child {
display:none;
}

See more explanation at: https://www.keptlight.com/page-header-or-not/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment