You can use output buffering to get the template output and return it in place of the emptied shortcode content:
if ($pos !== false)
ob_start;
get_template_part('content-gallery.php');
$contentgallery = ob_get_contents();
ob_end_clean();
return substr_replace( $content, $contentgallery, $pos, strlen($shortcode[0]) );`
}
EDIT It might make it easier to just replace the gallery shortcode?
remove_shortcode('gallery');
add_shortcode('gallery','my_content_gallery');
function my_content_gallery() {
ob_start;
get_template_part('content-gallery.php');
$contentgallery = ob_get_contents();
ob_end_clean();
return $contentgallery;
}
Related Posts:
- add_filter and changing output captions of image gallery
- Using variable from one filter in another filter
- Change default settings used by gallery shortcode
- Ajax, filters and shortcodes
- How to filter ‘post_gallery’ after all other filters/plugins etc
- How do I filter title and alt attributes in the gallery shortcode?
- WP Filter to change the URL of an Anchor wrapping the last gallery image
- Add Lightbox To WordPress Native Gallery
- add img class to native wordpress galleries
- How to display the content HTML of a page without displaying the gallery code as well
- Is it possible to override the default Gallery Settings form?
- get_post() containing gallery is outputting an unmatched closing div at the end of the content
- custom gallery filter with image caption as link title?
- Gallery stripped from excerpt of post
- Hooked into wp_get_attachment_caption to add content to the default description; not working for jetpack slideshow. Why?
- Add Index to Item in WordPress Gallery
- How to stop echoing gallery inside content?
- Changing WooCommerce Display Price Based on User Role & Category [closed]
- How to add headers to outgoing email?
- LESS CSS enqueue_style with add_filter to change rel attribute
- Remove Editor From Homepage
- Remove description from on Home
- What do add_filters() and apply_filter() do?
- How can I detect if a user changes their password?
- What to use instead of the content_save_pre filter?
- Moving sharedaddy buttons (in Jetpack) to the top of a post?
- How can I customize the wp_list_categories
- How can I reliably and globally disable wptexturize?
- Customise Jetpack Publicize text
- changing variable through filters or action hooks
- filter the_title problem in nav
- Add classname to the_category() function?
- Filter the URL of next_posts_link & previous_posts_link
- Sensei LMS Hooks to Remove Content
- How to re-enable a filter after disabling with __return_false
- Ignore dots when searching in the media library?
- Exclude One Category and its Subcategories using WP_LIST_FILTER
- Explanation for remove_filter used in the below code [closed]
- Gutenberg disable the “block” tab in right sidebar
- Where is this inline CSS code [closed]
- When to use actions and when to use filters
- add_filter to ‘woocommerce_before_main_content’ [closed]
- Editing
- add_filter to apply_filters that exists within class
- Why won’t my preg_replace work with content_save_pre?
- Echoing Categories only if they’re a child of a given category
- How Does comment_author Filter Work?
- Add ‘data-text’ attribute to TagCloud HTML
- Why in archive page doesn´t show read more button with excerpt?
- Removal of Jetpack OG Tags from old blog site
- Adding a title prefix with the the_title filter
- get_posts() and filters
- Don’t see add_filter result in the site front page
- How can I include an existing custom sitemaps listing in wp-sitemap.xml?
- Display Externally Retrieved Data within a Custom Template
- Can the wordpress color palettes by changed through Javascript?
- Filter on the_content doesn’t update the content being searched via register_rest_route
- Where to add_filter in theme functions.php?
- Cannot change the definition of AUTOMATIC_UPDATER_DISABLED
- How do I add a checkmark to my-sites save settings hook
- tag removed not using a filter
- WordPress Image update filter
- How to remove this filter?
- Why does WordPress strip custom HTML that are form elements and theme SVG icons?
- Trouble using remove_filter to override function in parent theme
- Load Posts’ individual body content on index starting at char 200 of each post
- How to combine multiple body classes
- Prepending character(s) to a custom tag title?
- How to replace username with email address in users table
- Modify existing plugin function with add_filter
- include specific Pages to wp_list_pages with filter
- why require – does not load filter
- term_link filter rewrite link only applying half of condition?
- How can I filter tag_description()?
- What is the action hook to use if you want to capture the new password during password change?
- Register users by e-mail
- Making an add_filter() call from within an add_filter() call
- Filter causing loss of _wp_attachment_metadata
- Action hook to control access to certain parts of my site
- Finding actual functions added to hooks and filters
- How to apply filter on get_the_post_thumbnail()
- How can I tranlslate post date in italian?
- Use alternative front page if cookie is set
- Having wp-admin on different domain
- Use a functions in functions.php to remove a string for template theme
- Setting the page title in a plugin, but not outside my plugin
- how to output HTML tags in post_content and not as plain text
- Security question – Display a General Custom Login Error Message
- Add filter conditionally to a page
- How to apply a filter to everything?
- WP Job Manager – display search results from custom search form in taxonomy-job_listing_category page
- Conditionally (cpt) filter previous and next_post_link
- changing size image within the content
- Remove action added from class
- Identify admin/logout and more filters
- Sanitizing a custom query’s clauses
- How can I display wp_link_pages before a shortcode, if it is used, or display after content?
- How to create a list of terms who’s posts also have a predefined external term?
- Better way to change the default password reset url with the woocommerce one?
- woocommerce_coupon_is_valid_for_product not working to exclude specific product tag