• I added image gallery to my page via Add Media > Create Gallery. I don’t want to output default html of the gallery, neither is sufficient the option to change such attributes as itemtag, icontag, and captiontag. I want my own html entirely.

    I’ve tried to hook to post_gallery and grab src of images that are included as a gallery into that page and output them:

    add_filter( 'post_gallery', 'my_name_page_gallery', 10, 2 );
    function my_name_page_gallery($output, $attr) {
        $output = get_post_gallery_images();
        return $output;
    }

    But I get the following error:

    Maximum function nesting level of ‘512’ reached, aborting! in /wp-includes/shortcodes.php on line 234

    What am I doing wrong? How do I get gallery images’ urls and output custom html?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You have coded a recursive routine (one that calls itself).
    Your function is called from within the gallery shortcode handler. You are calling get_post_gallery_images(), which calls get_post_gallery(), which calls get_post_galleries(), which expands the shortcode by calling gallery_shortcode() which is where your filter is, and on and on 512 times until it is stopped.

    So if you want to supply the HTML, you will have to do it without calling one of the functions in the series that gets caught in the recursive loop. That’s why the gallery shortcode function doesn’t call any of the others, but generates it independently.

    The easiest way to affects the gallery is to call add_theme_support('html5', 'gallery'); so it uses html5 markup and then style it the way you want.

    On my custom theme I have replaced the default gallery shortcode with a custom shortcode that renders my custom HTML using Bootstrap and BlueImp Gallery.

    I can’t find the tutorial I followed but this one is similar : https://ieg.wnet.org/2016/02/replacing-default-wordpress-gallery-shortcode/

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Gallery custom html output’ is closed to new replies.