WordPress.org

Ready to get started?Download WordPress

Forums

How To implement Thickbox to all images which contain a refered link? (2 posts)

  1. fliptronic
    Member
    Posted 5 years ago #

    I want, that all preview pictures in my blog, which have a refered link to a larger one, to be open by Thickbox without adding the class (class="thickbox") to each image in the code. For this purpose I've found a Plugin which is called Thickboxalize, but it doesn't work.

  2. fliptronic
    Member
    Posted 5 years ago #

    Thickbox has to be loaded by a plugin or manually in the header between this two tags:

    <?php wp_head(); ?>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/thickbox/thickbox.css" type="text/css" media="screen, projection">
    <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/thickbox/jquery-latest.pack.js"></script>
    <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/thickbox/thickbox.js"></script>
    </head>

    As a matter of course the jQuery-Framework and Thickbox have to be copied in your theme or you use the already existing one in wp-includes/js/.

    Then you add the following code (found on bueltge.de in functions.php:

    function fb_add_thickbox($content){
    
    	$content = preg_replace('/<a(.*?)href="(.*?).(jpg|jpeg|png|gif|bmp|ico)"(.*?)><img/U', '<a$1href="$2.$3" $4 class="thickbox"><img', $content);
    
    	return $content;
    }
    add_filter('the_content', 'fb_add_thickbox', 2);

    Thanks to bueltge!!!

Topic Closed

This topic has been closed to new replies.

About this Topic