Guest User

Untitled

a guest
Jul 27th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. // Hide the first image from WordPress post content
  2. function hide_first_image_from_post_content($content) {
  3. // Check if we are on a single post page
  4. if (is_single()) {
  5. // Find the first image in the post content
  6. preg_match('/<img.*?>/', $content, $matches);
  7. if (!empty($matches)) {
  8. // Replace the first image with an empty string to hide it
  9. $content = str_replace($matches[0], '', $content);
  10. }
  11. }
  12. return $content;
  13. }
  14. add_filter('the_content', 'hide_first_image_from_post_content');
  15.  
Advertisement
Add Comment
Please, Sign In to add comment