The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Default parameters/attributes for post gallery shortcode (3 posts)

  1. Kaleb.G
    Posted 5 years ago #

    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;
            //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!

  2. lancemonotone
    Posted 5 years ago #

    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]

  3. chavo
    Posted 4 years ago #

    Hi lancemonotone. Can you post your entire function?

    Thanks in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic