Title: Default parameters/attributes for post gallery shortcode
Last modified: August 19, 2016

---

# Default parameters/attributes for post gallery shortcode

 *  [Kaleb.G](https://wordpress.org/support/users/kalebg/)
 * (@kalebg)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/default-parametersattributes-for-post-gallery-shortcode/)
 * I’d like a simple method to set default parameters/attributes for post gallery
   shortcode, even if I have to write my own plugin. In my case, I wanted all galleries
   to link directly to the files themselves by default. Unfortunately, there is 
   no way to simply reference and return the attributes.
 * Here’s the method I’m currently using by editing wp-includes/media.php:
 *     ```
       function gallery_shortcode($attr) {
       	global $post, $wp_locale;
   
       	static $instance = 0;
       	$instance++;
   
               //KRG: Added for Arkmagia Gallery Shortcode.
       	// Allow plugins/themes to override the default gallery attributes.
       	$attr = apply_filters('post_gallery_attr', '', $attr);
   
       	// Allow plugins/themes to override the default gallery template.
       	$output = apply_filters('post_gallery', '', $attr);
       	if ( $output != '' )
       		return $output;
       ...
       ```
   
 * I then have a plugin to set the default params:
 *     ```
       add_filter('post_gallery_attr', 'arkmagia_gallery_shortcode');
   
       function arkmagia_gallery_shortcode($attr) {
       	if ( !isset( $attr['link'] ) ) {
       		$attr['link'] = 'file';
       	}
   
       	return $attr;
       }
       ```
   
 * Though there is also another problem in that if I wanted any [gallery] instances
   to link to actual attachment pages, there is no explicit ‘link’ attribute value
   for that…
 * Any thoughts? Thanks for reading!

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

 *  [lancemonotone](https://wordpress.org/support/users/lancemonotone/)
 * (@lancemonotone)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/default-parametersattributes-for-post-gallery-shortcode/#post-1822603)
 * You can override the WP gallery shortcode and use your own function, in which
   you can set your own default options in the shortcode_atts() portion. Here is
   my own function which sets these defaults:
    ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order
   ID’, ‘id’ => $post->ID, ‘container’ => ‘ul’, ‘itemtag’ => ‘li’, ‘icontag’ => ‘
   span’, ‘captiontag’ => ‘span’, ‘columns’ => 0, ‘size’ => ‘full’, ‘include’ =>”,‘
   exclude’ => ”, ‘meta’ => 0, ‘link’ => ‘none’, ‘exclude_thumb’ => true
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com)]_
 *  [chavo](https://wordpress.org/support/users/chavo/)
 * (@chavo)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/default-parametersattributes-for-post-gallery-shortcode/#post-1822659)
 * Hi lancemonotone. Can you post your entire function?
 * Thanks in advance.

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

The topic ‘Default parameters/attributes for post gallery shortcode’ is closed to
new replies.

## Tags

 * [attr](https://wordpress.org/support/topic-tag/attr/)
 * [attributes](https://wordpress.org/support/topic-tag/attributes/)
 * [default](https://wordpress.org/support/topic-tag/default/)
 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [gallery_shortcode](https://wordpress.org/support/topic-tag/gallery_shortcode/)
 * [parameters](https://wordpress.org/support/topic-tag/parameters/)
 * [post_gallery](https://wordpress.org/support/topic-tag/post_gallery/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [chavo](https://wordpress.org/support/users/chavo/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/default-parametersattributes-for-post-gallery-shortcode/#post-1822659)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
