Best approach when modifying the Media Manager

This is my go to snippet for things like this. <?php add_action(‘print_media_templates’, function(){ // define your backbone template; // the “tmpl-” prefix is required, // and your input field should have a data-setting attribute // matching the shortcode name ?> <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> <label class=”setting”> <span><?php _e(‘My setting’); ?></span> <select data-setting=”my_custom_attr”> <option value=”foo”> Foo </option> … Read more

Make a really simple gallery structure

Use your own gallery shortcode handler – something like this in your functions.php: function __my_gallery_shortcode( $attr ) { // render the gallery the way you want it } add_shortcode( ‘gallery’, ‘__my_gallery_shortcode’ ); To get you started, you could just copy the code from the default handler gallery_shortcode(), and edit as you require.

Custom wordpress gallery option

WordPress doesn’t make it very easy to modify aspects of the gallery shortcode. Some attributions: Thanks to user peterbra for really putting the whole thing together a year ago. Thanks to user birgire for coming up with a solution as far as adding the attribute in a meaningful way. The other option besides birgires ( … Read more

get_post_gallery with Gutenberg

Using birgire’s suggestions, I came up with the following solution that is working well with both the old pre-WP 4.x data and the newer posts that have been added under 5.0. // if there is a gallery block do this if (has_block(‘gallery’, $post->post_content)) { $post_blocks = parse_blocks($post->post_content); $ids = $post_blocks[0][attrs][ids]; } // if there is … Read more

How to specify a class added to my gallery

Here are three methods Approach #1 It’s common to wrap the output with custom HTML. We can do that by using the post_gallery filter and the gallery_shortcode() callback: /** * HTML Wrapper – Support for a custom class attribute in the native gallery shortcode */ add_filter( ‘post_gallery’, function( $html, $attr, $instance ) { if( isset( … Read more

How can I alter the [gallery] markup?

Thanks for your replies, Jan & Rarst. They pointed me in the right direction. Here’s what I ended up with. This disables shortcodes in the content. Perfect for this site & the function gets attached images & spits them out as a list. (I found the function somewhere & slimmed it down a little) // … Read more