Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 0 down vote accepted

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.

share|improve this answer
    
Okay I enquaue the scripts from functions. Do I do right if just include the enquaue or should I use init? –  Danny Style Jan 4 '12 at 17:49
    
If you're loading multiple, or using conditionals (i.e. only load script X on single posts and script Y on the home page) than an init is a better bet. But either way you should be fine. –  Norcross Jan 4 '12 at 17:54
    
Thank you very much it's succesfull .. I'm lucky with ya! –  Danny Style Jan 4 '12 at 18:23

All you need to do is a simple call in your functions.php:

add_action( 'wp_enqueue_scripts', 'add_thickbox' );

That’s it. WordPress will now enqueue jQuery and the thickbox script. By default, linked images aren’t thickboxy yet. You need to:

  1. Add a class thickbox to the links manually/per PHP, or
  2. Use a second script to add these classes automagically.

Sample code for footer.php:

<script>
jQuery('a img.size-medium').parent().addClass('thickbox').attr('rel', 'page');
</script>
<?php
wp_footer();

This code adds the class thickbox to all links around medium sized images, and it groups these links to enable the next/prev navigation links.

Now you get a basic thickbox with translated navigation links:

enter image description here

Since this is a script managed by the core it is not keyboard user friendly: The arrow keys don’t do anything. If you need a more usable solution – take a plugin.

Another note: Thickbox may be removed sooner or later from the core. See Ticket 10955.

share|improve this answer
    
Awesome. Thank you @toscho ! –  mattrepublic Feb 22 '12 at 23:55

Hi can any one help me to resolve my problem::

Here it my code

<a href="'. site_url("wp-admin/admin-ajax.php?action=user_avatar_add_photo&step=1&uid="). $myUID . '&TB_iframe=true&width=720&height=450" title="Upload and Crop an Image to be Displayed" >' . ( 'Update Picture','wp-members' ) . '</a>

this piece of code i'm trying to use in Wp-admin profile it is working fine but.. there is a problem... i.e while I try to chance the user avatar from front end TB_ifram is not popping up... it is spreading to whole webpage...

here it's image: enter image description here here i need to popup the TB_Ifram content frame from the front end... plz give me suggestion that would be great to you..

regards

share|improve this answer
    
Welcome to WordPress SE. If you have a question, please start a new question rather than posting it as an answer on another question. Thanks! –  Dan Mar 21 at 15:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.