Skip to content

Instantly share code, notes, and snippets.

@finalwebsites
Last active August 19, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finalwebsites/8116e2ced4b594d02c2d73e7f1412063 to your computer and use it in GitHub Desktop.
Save finalwebsites/8116e2ced4b594d02c2d73e7f1412063 to your computer and use it in GitHub Desktop.
Use the jQuery thickbox plugin for your WordPress galleries (add code to your theme's function.php file)
function add_thickbox_attributes_gallery_link( $anchor_tag, $image_id ) {
$image = get_post( $image_id );
if( isset($image->post_parent)) {
$rel = '<a class="thickbox" rel="attached-to-'.intval($image->post_parent).'"';
$anchor_tag = str_replace('<a', $rel, $anchor_tag);
}
return $anchor_tag;
}
add_filter('wp_get_attachment_link', 'add_thickbox_attributes_gallery_link', 1, 2);
function load_thickbox() {
if (is_single() || is_page()) {
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
}
}
add_action('wp_enqueue_scripts', 'load_thickbox');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment