You could use preg_replace()
but I think it’s much easier to overwrite the $output
via the post_gallery
filter and then remove the filter after the first run:
/**
* Remove the output of the first gallery
*
* @param string $output
* @param array $attr
* @return string $output
*/
function wpse125903_remove_the_first_gallery( $output, $attr )
{
// Run only once
remove_filter( current_filter(), __FUNCTION__ );
// Override the first gallery output
return '<!-- gallery 1 was here -->'; // Must be non-empty.
}
add_filter( 'post_gallery', 'wpse125903_remove_the_first_gallery', 10, 2 );
This should remove only the first gallery in your posts.
Related Posts:
- Turn a URL into an Attachment / Post ID
- How to mark every 3rd post
- ZIP up all images displayed in a [gallery] and offer as download link
- Count posts within a custom post type and specific taxonomy and terms?
- How to Display a List of Users Who Have Made at Least 1 Post?
- How to Display Network Post Count?
- Add existing images from Media Library in to custom gallery
- How to cache a shortcode functions output?
- Count posts in category including child categories
- Can I load posts via Ajax?
- Count singular post views automatically
- Set font size automatically according to number of words in post
- How do I change the gallery that is inserted in the post?
- Network wide post count (WP Multisite)
- Redirect based on user post count
- Alternate custom content in the loop
- Show that current post is number X out of X
- Show the author’s count of total amount of posts assign to a custom taxonomy term
- Double count view in archive.php
- Count to how many categories a post belongs to
- How can I remove “”
- Add container div to gallery using post_gallery
- Count total number across post types
- Count search results in heading
- Get image from post’s gallery
- Should a photo gallery be in a post or on a page?
- Counter of posts ever posted – even deleted ones
- Display Published Posts Count for Certain Time Period
- How is a gallery associated with some post in database?
- How can I get global $post to work for CPT and update user?
- posts_per_page option limits the number of Gallery items
- plugin to post from admin to flickr [closed]
- Display Notification Bar on Header on Certain Post Count
- Show posts count for Categories and Tags in wp_nav_menu
- How to add category post count in main navigation menu [closed]
- Count number of posts of current month
- Howto show comment count by post in post?
- Counter is skipping post when I still want it visible [closed]
- Count several post tags
- Get post number both in the loop and in the post
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- Count the number of a post types associated with another post type
- Echo the number of posts being displayed
- Display amount of pending posts in back/front end
- Count user posts and store the number for later use
- How to get the next and previous image title from attachment or gallery?
- why the posts queried from sql is more than those showed on the page?
- WordPress as CMS: How to manage/handle images assigned to a post as full-sized background images in a slideshow?
- Count the total views of all user posts published
- How can i showcase all my galleries?
- Rewrite image links from attachment id to attachment link
- Author post count in category
- Set post title font size automatically according to number of words in post title
- Display image gallery if more than 1 image
- Show post count in custom taxonomy page
- Count singular post views automatically
- How to count posts in tags within time limit
- Display Custom Post Category Count & WordPress Category Count Using Shortcode
- Counting Posts by Category
- show image gallery in archives or category page
- Display number of post published every day
- Colorbox not working on native WordPress gallery when gallery is loaded thru AJAX
- Retrieve posts inside foundation tabs and tab-content split by 3 per row
- Integrate video and iframe in a post type gallery
- Alternative content between posts no repetition
- count_posts to a standalone link
- How to control Post view count incresing in sidebar widget posts too?
- Post gallery as carousel
- How to use extract shortcode in loop?
- Gallery just showing plain short code like [gallery ids="240,236,275"]. how to solve this?
- WP Gallery Image Page Issue When 2 galleries share one image
- How to mark every 3rd post
- Add a minimum word count to Excerpt (and how to force Excerpt as a rule for WyPiekacz)
- standard wpGallery for post won’t work
- Multiple post back-to-back display only one gallery
- How to limit the number of posts a user can publish based on user type
- ho can I get the number of the current post instead of the post id?
- post_count not working
- Adding Count Post in Page
- Count words for all posts by all authors
- Word count for all posts of all authors
- Display post count on archive page in reverse order
- How to move all images in a post to a single gallery for a bunch of posts?
- How can I display 7 posts on the home page, but 9 posts on the subsequent pages?
- 404 error after publishing a post
- Showing Thumbnail from Previous and Next Posts
- Reset/Reorder posts ID in the MySQL wp_posts table
- Apply a style for 4 blogs and another style for the next 4 blogs in wordpress blog page?
- Listing Specific Categories from Current Post with Depth
- outputting posts’ taxonomies: cant get ‘get_the_taxonomies’ working
- Query for first 3 posts to change the look and feel
- Getting blog pagination to work on page set as front page
- Get featured image on hover of post title [closed]
- Changing wp_link_pages() to “Next Page” and “Previous Page” buttons?
- Filter posts by month (dropdown)
- Redirect old Posts URL to new URL
- How can I use the “Your latest posts” as a template?
- Extra Theme – Fit image inside of Featured Post Slider
- How can I show the positive and negative comments for a same post separately?
- How to monitor the first publish date?