Last active
August 19, 2018 13:44
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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