Title: Adding custom attribute to [gallery] shortcode
Last modified: August 21, 2016

---

# Adding custom attribute to [gallery] shortcode

 *  [Swayne3](https://wordpress.org/support/users/swayne3/)
 * (@swayne3)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/adding-custom-attribute-to-gallery-shortcode/)
 * Hi,
    I’m modifying one WP theme and I’d really like to add a simple attribute
   to gallery shortcode whether to crop image thumbnail or not. And then in the 
   process of creating a thumbnail I would like to just specify
 *     ```
       if crop == 'yes' { do this }
       else { do that }
       ```
   
 * Is that possible? And if so than how? Thanks for any answer!
 * Edit:
    Theme has it’s own registered gallery shortcode with some modifications
   I think, but I simply can’t make this work…

Viewing 1 replies (of 1 total)

 *  Thread Starter [Swayne3](https://wordpress.org/support/users/swayne3/)
 * (@swayne3)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/adding-custom-attribute-to-gallery-shortcode/#post-3947029)
 * Ok, got it. Just added ‘crop’ into
 *     ```
       extract( shortcode_atts( array(
       		'order'      => 'ASC',
       		'orderby'    => 'menu_order ID',
       		'id'         => $post->ID,
       		'itemtag'    => 'dl',
       		'icontag'    => 'dt',
       		'captiontag' => 'dd',
       		'columns'    => 5,
       		'size'       => 'gallery',
       		'exclude'    => '',
       		'include'    => '',
       		'ids'	     => '',
       		'crop'	     => ''
       	), $attr ) );
       ```
   
 * then
    `$crop = tag_escape($crop);` and at the end
 *     ```
       if ( $crop == "yes" )
            $img_src = crop function
       else
            $img_src = normal resize
       ```
   
 * But now I have to manually add ‘crop=”yes”‘ to the shortcode in the post editor.
   Is there a way to implement simple dropdown select with only two options ‘Crop
   Yes/No’ into Gallery editor?

Viewing 1 replies (of 1 total)

The topic ‘Adding custom attribute to [gallery] shortcode’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [Swayne3](https://wordpress.org/support/users/swayne3/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/adding-custom-attribute-to-gallery-shortcode/#post-3947029)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
