WordPress Troubleshooting

Fix WordPress 3.4 Image Caption Bug with Thesis Theme Without Upgrading Thesis

If you are using Thesis theme under V1.8.5, you must have the problem: Images not aligning properly in articles after upgrading to WordPress 3.4

Fix WordPress 3.4 Image Caption Bug with Thesis Theme Without Upgrading Thesis

Fix WordPress 3.4 Image Caption Bug with Thesis Theme Without Upgrading Thesis,Like THIS!!! Thesis 1.8.2

Why this problem occurs?

Because WordPress 3.4 changed image caption shortcode structure:

Change the image caption shortcode format to {caption shortcode}{anchor tag}{image tag}caption text + html{close anchor tag}{close caption shortcode} that way HTML tags in captions are better supported and the shortcode wouldn’t break when using the wrong quotes.

How to Solve this problem?

As many of  us have made a lot of customization to old Thesis theme and is quite impossible to “upgrade to 1.8.5” without any loss. So how can we solve this image caption problem without upgrading Thesis, but trick the theme instead? I dug into the theme  code and finally got the answer. Follow my steps below:

1. Open file thesis\lib\functions\launch.php  , locate the following code with search function of your text editor:

// Use Thesis image captioning
add_shortcode('wp_caption', 'thesis_img_caption_shortcode');
add_shortcode('caption', 'thesis_img_caption_shortcode');

Delete them! The function of this code is to replace WordPress caption shortcode with Thesis own caption shortcode

2. So where is Thesis own Caption shortcode function? Open thesis\lib\functions\content.php and locate the code block:

 * Handle  and  shortcodes.
 * This function is mostly copy pasta from WP (wp-includes/media.php),
 * but with minor alteration to play more nicely with our styling.
 * The supported attributes for the shortcode are 'id', 'align', 'width', and
 * 'caption'. These are unchanged from WP's default.
 * @since 2.5
 * @param array $attr Attributes attributed to the shortcode.
 * @param string $content Optional. Shortcode content.
 * @return string
function thesis_img_caption_shortcode($attr, $content = null) {
    // Allow this to be overriden.
    $output = apply_filters('thesis_img_caption_shortcode', '', $attr, $content);

    if ($output != '')
        return $output;

    // Get necessary attributes or use the default.
        'id'    => '',
        'align'    => 'alignnone',
        'width'    => '',
        'caption' => ''
    ), $attr));

    // Not enough information to form a caption, so just dump the image.
    if (1 > (int) $width || empty($caption))
        return $content;

    // For unique styling, create an ID.
    if ($id)
        $id = ' id="' . $id . '"';

    // Format our captioned image.
    $output = "<div$id class=\"wp-caption $align\" style=\"width: " . (int) $width . "px\">
    <p class=\"wp-caption-text\">$caption</p>\n</div>";

    // Return our result.
    return $output;

Delete them! This function is Thesis image caption function.

3. That’s it! Your old Thesis theme is now OK with WordPress 3.4 on Image Caption Shortcode. Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *