Last active
January 16, 2021 16:49
-
-
Save Santel/8451460 to your computer and use it in GitHub Desktop.
Remove first image from WordPress post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//* 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/