Ready to get started?Download WordPress


Gallery with No Image Links
Update (2 posts)

  1. kasparsj
    Posted 1 year ago #

    Hi sators,

    A better implementation would be by subscribing to the "post_gallery" filter:

    function gallery_link_none($output, $attr = array()) {
        if (isset($attr["link"]) && $attr["link"] == "none")
            return preg_replace(array('/<a[^>]*>(<img[^>]*>)<\/a>/'), '$1', $output);
        return $output;
    add_filter('post_gallery', 'gallery_link_none', 10001, 2);

    This way it works with custom gallery plugins and also addresses the issue found by "livesimplybyannie".

    Can you please update the plugin?



  2. helgatheviking
    Posted 1 year ago #

    I love this idea, but it doesn't seem to remove any links for me.

    [gallery ids="24,25,26,27" size="full" link="none" columns="1"]

    Just produces linked images like normal.

    I think because in the gallery shortcode callback you have:

    // Allow plugins/themes to override the default gallery template.
    	$output = apply_filters('post_gallery', '', $attr);
    	if ( $output != '' )
    		return $output;

    which means your filter must actually create some markup, or the shortcode will just proceed to do its default markup.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic