Update:
It looks like there exists an attribute link="none"
after all π
For example:
So we don’t need to reinvent the wheel, like in my previous answers π
Previous: Plugin to handle link="no"
in the gallery shortcode:
Here’s a demo plugin to add the option to remove the image links in the gallery.
You can use the link="no"
option to remove the links, for example:
Create the folder /wp-content/plugins/gallery-without-links/
and add the file gallery-without-links.php
to it, containing the following code:
<?php
/**
* Plugin Name: Gallery without links
* Plugin URI: http://wordpress.stackexchange.com/a/130349/26350
* Description: Gallery with the link='no' option to remove links.
*/
/**
* Init the WPSE_No_Gallery_Links class
*/
if( ! class_exists( 'WPSE_No_Gallery_Links' ) ):
add_action( 'init', array( 'WPSE_No_Gallery_Links', 'get_instance' ) );
class WPSE_No_Gallery_Links
{
static private $instance = NULL;
protected $nrofimgs = 0;
protected $counter = 0;
public function __construct()
{
add_filter( 'shortcode_atts_gallery', array( $this, 'shortcode_atts_gallery' ) );
}
static public function get_instance()
{
if ( NULL === self :: $instance )
self :: $instance = new self;
return self :: $instance;
}
public function wp_get_attachment_link( $link ){
$this->counter++;
if( $this->counter >= $this->nrofimgs )
{
$this->counter = 0;
remove_action( 'wp_get_attachment_link', array( $this, 'wp_get_attachment_link' ) );
}
return strip_tags( $link, '<img>' );
}
public function shortcode_atts_gallery( $atts ) {
if( 'no' === $atts['link'] )
{
if( isset( $atts['include'] ) )
{
$this->nrofimgs = count( explode( ',', $atts['include'] ) );
add_action( 'wp_get_attachment_link', array( $this, 'wp_get_attachment_link' ) );
}
}
return $atts;
}
} // end of class
endif;
Previous answer:
Here is one idea:
The gallery shortcode callback is using the wp_get_attachment_link()
function to generate the link to each image in the gallery. We can therefore use the wp_get_attachment_link
filter to strip out the <a>
tags.
You could then modify your code snippet to:
<div class="well well-clear" style="padding-bottom: 0; margin-bottom: 0;">
<?php
add_action( 'wp_get_attachment_link', 'custom_wp_get_attachment_link' );
echo do_shortcode('');
remove_action( 'wp_get_attachment_link', 'custom_wp_get_attachment_link' );
?>
</div>
where:
/**
* Strip all tags except the <img> tag
*/
function custom_wp_get_attachment_link( $link )
{
return strip_tags( $link, '<img>' );
}