Adding jquery and thickbox to WordPress theme

I would like to add thickbox for the template which I develop to WordPress. At this time I’m trying with a clean template that have only header.php, footer.php,index.php, and functions.php.

I’ve included the <?php wp_head(); ?> into header.php and the <?php wp_footer(); ?> into footer.php.

I’ve included the wp_head like this:

<?php
wp_enqueue_script('jquery');
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
wp_head();
?>

I’ve changed the gallery link classes to thickbox with this code in functions.php

<?php add_filter( 'wp_get_attachment_link', 'sant_prettyadd');

function sant_prettyadd ($content) {
    $content = preg_replace("/<a/","<a class=\"thickbox[slides]\"",$content,1);
    return $content;
}
?>

When I’m clicking on to a gallery image it should open with thickbox but it opens the imagefile only.

3 s
3

You need to use the wp_enqueue_script function (in your functions.php file) to call the relevant scripts you need. It allows for both built-in libraries and to add any custom that you’re including in your theme.

Leave a Comment