• 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)
  • 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. Please use the pastebin]

    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.