Title: Bug? post_gallery filter parameter always empty string
Last modified: August 19, 2016

---

# Bug? post_gallery filter parameter always empty string

 *  Resolved [cannibalsmith](https://wordpress.org/support/users/cannibalsmith/)
 * (@cannibalsmith)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/bug-post_gallery-filter-parameter-always-empty-string/)
 * In `functions.php` of my custom theme:
 *     ```
       function custom_gallery($attr) { /* .. */ }
       add_action('post_gallery', 'custom_gallery');
       ```
   
 * The `$attr` is always an empty string. But it should be an array. When I look
   at the `wp-includes/media.php` line 597:
 *     ```
       function gallery_shortcode($attr) {
       global $post;
       // Allow plugins/themes to override the default gallery template.
       $output = apply_filters('post_gallery', '', $attr);
       ```
   
 * It seems to be a bug. [But then again…](http://core.trac.wordpress.org/ticket/6954)
 * What to do? How do I obtain proper `$attr` value?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/bug-post_gallery-filter-parameter-always-empty-string/#post-1041791)
 * The `$attr` value comes from the gallery shortcode. If you look around 10 lines
   further down in `wp-includes/media.php`, you’ll see:
 *     ```
       extract(shortcode_atts(array(
       		'order'      => 'ASC',
       		'orderby'    => 'menu_order ID',
       		'id'         => $post->ID,
       		'itemtag'    => 'dl',
       		'icontag'    => 'dt',
       		'captiontag' => 'dd',
       		'columns'    => 3,
       		'size'       => 'thumbnail'
       	), $attr));
       ```
   
 * So your custom_gallery function could use exactly the same `extract` function
   but you can now insert your own gallery ordering and markup etc. I use a similar
   custom gallery function to output the final gallery as an unordered list and 
   stop the gallery CSS from being rendered within the `<body>` of a page (which**
   is** a bug).
 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/bug-post_gallery-filter-parameter-always-empty-string/#post-1041919)
 * The current gallery code in WP is correct. You should be using the filter hook
   to customize the gallery:
 *     ```
       add_filter( 'post_gallery', 'my_gallery_shortcode', 10, 2 );
   
       function my_gallery_shortcode( $output, $attr ) {
   
       	/* Custom gallery shortcode. */
   
       }
       ```
   
 *  Thread Starter [cannibalsmith](https://wordpress.org/support/users/cannibalsmith/)
 * (@cannibalsmith)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/bug-post_gallery-filter-parameter-always-empty-string/#post-1042003)
 * Thanks, greenshady. My mistake was not passing `$accepted_args` to `add_filter`.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Bug? post_gallery filter parameter always empty string’ is closed to 
new replies.

## Tags

 * [gallery](https://wordpress.org/support/topic-tag/gallery/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [cannibalsmith](https://wordpress.org/support/users/cannibalsmith/)
 * Last activity: [17 years, 1 month ago](https://wordpress.org/support/topic/bug-post_gallery-filter-parameter-always-empty-string/#post-1042003)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
