apply_filters( 'post_gallery', string $output, array $attr, int $instance )

Filters the default gallery shortcode output.


Description Description

If the filtered output isn’t empty, it will be used instead of generating the default gallery template.

Top ↑

See also See also


Top ↑

Parameters Parameters

$output

(string) The gallery output. Default empty.

$attr

(array) Attributes of the gallery shortcode.

$instance

(int) Unique numeric ID of this gallery shortcode instance.


Top ↑

More Information More Information

This filter allows plugins and themes to override the default gallery template (i.e. what the gallery shortcode returns).


Top ↑

Source Source

File: wp-includes/media.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
4.2.0 The $instance parameter was added.
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by stevenlinx

    Example Migrated from Codex:

    Hook into the gallery shortcode and replace its output with your own.

    add_filter( 'post_gallery', 'my_gallery_shortcode', 10, 3 );
    
    function my_gallery_shortcode( $output = '', $atts = null, $instance = null ) {
    	$return = $output; // fallback
    
    	// retrieve content of your own gallery function
    	$my_result = get_my_gallery_content( $atts );
    
    	// boolean false = empty, see http://php.net/empty
    	if( !empty( $my_result ) ) {
    		$return = $my_result;
    	}
    
    	return $return;
    }
    

Top ↑

You must log in before being able to contribute a note or feedback.