Beim Einfügen einer Galerie wird der folgende Shortcode hinzugefügt:
[gallery columns="6" ids="18,150,146,23,147,17,21,20,22"]
Ich möchte, dass link = "file" automatisch als letztes Attribut hinzugefügt wird, wenn ein Shortcode hinzugefügt wird. Wie so:
[gallery columns="6" ids="18,150,146,23,147,17,21,20,22" link="file"]
Sie können den Shortcode-Handler übernehmen und das Attribut auf einen Wert Ihrer Wahl setzen. Rufen Sie dann den systemeigenen Rückruf für diesen Shortcode an.
add_shortcode( 'gallery', 'file_gallery_shortcode' );
function file_gallery_shortcode( $atts )
{
$atts['link'] = 'file';
return gallery_shortcode( $atts );
}
Es gibt einen neuen shortcode_atts_{$shortcode}
Filter in WordPress 3.6
nach Mark Jaquith .
Sie können den shortcode_atts_gallery
-Filter verwenden, um das link='file'
-Attribut zu erzwingen:
add_filter('shortcode_atts_gallery','overwrite_gallery_atts_wpse_95965',10,3);
function overwrite_gallery_atts_wpse_95965($out, $pairs, $atts){
// force the link='file' gallery shortcode attribute:
$out['link']='file';
return $out;
}
wenn Sie ein Upgrade auf 3.6
durchgeführt haben.
Sie können es in /wp-includes/shortcodes.php
aus dem Core-Trac-Trunk auschecken:
http://core.trac.wordpress.org/browser/trunk/wp-includes/shortcodes.php#L316