How To Filter caption-Shortcode in WordPress

December 29th, 2009 By WP Tricks Posted in Tricks

WordPress 2.5 and up added new featured that called wp-caption, this is nice custom, you can add extra text on your image post, beside that tricks you can explore more with this featured. My bigg problem is the default wp-caption is added extra inline style. This inline style added extra padding on the left and right on your wp-caption. If you wp-caption style is using standard method of wordpress, you didn’t need this tricks.

But if you theme design need another style, like disable padding on your wp-caption, you’ll need it. Let’s explore more details.

Sponsored Links

On this wp tricks, we will modified default function on wp-caption and hook it with this modified caption. All need to do, is open functions.php on your theme and write this code

add_shortcode('wp_caption', 'fixed_img_caption_shortcode');
add_shortcode('caption', 'fixed_img_caption_shortcode');
function fixed_img_caption_shortcode($attr, $content = null) {
	// Allow plugins/themes to override the default caption template.
	$output = apply_filters('img_caption_shortcode', '', $attr, $content);
	if ( $output != '' ) return $output;
	extract(shortcode_atts(array(
		'id'=> '',
		'align'	=> 'alignnone',
		'width'	=> '',
		'caption' => ''), $attr));
	if ( 1 > (int) $width || empty($caption) )
	return $content;
	if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
	return '<div ' . $id . 'class="wp-caption ' . esc_attr($align)
	. '" style="width: ' . ((int) $width) . 'px">'
	. do_shortcode( $content ) . '<p class="wp-caption-text">'
	. $caption . '</p></div>';
}

And done, you can check it on your theme and the inline style is gone ;) This tricks I got it from WordPress.org forum, WP Engineer show different method. Do you have another solutions to do this? Share to me

How To Filter caption-Shortcode in WordPress On The NET

Filter caption-Shortcode in WordPress - The Caption shortcode ...

The title may not speak for itself and therefore I will explain a little more on the topic and do read more

Source: http://wpengineer.com/917/filter-caption-shortcode-in-wordpress/

How To Filter caption-Shortcode in WordPress # WordPress Tricks & Tips

WordPress 2.5 and up added new featured that called wp-caption, this is nice custom, you can add extra text on your image post, beside that tricks you can read more

Source: http://wptricks.net/how-to-filter-caption-shortcode-in-wordpress/

Filter caption-shortcode in WordPress / JAUHARI

For many reason, there are a lot of blogger using WordPress as they publishing platform. Free, easy to use and a lot of extend available on the net. WordPress read more

Source: http://www.jauhari.net/filter-caption-shortcode-in-wordpress.jsp

img_caption_shortcode hook - WordPress source view -- Adam Brown ...

Detailed information about every action hook and filter used in WordPress. Makes Plugin API easier to use. Lists appearance, file location, and deprecation data for every hook. read more

Source: http://adambrown.info/p/wp_hooks/hook/img_caption_shortcode?version=2.6&file=wp-includes/media.php

How to Detect Category ID using the Category Slug in WordPress ...

How To Filter caption-Shortcode in WordPress # WordPress Tricks & Tips. Detect Category ID using the Category Slug in WordPress; Added Permalinks Shortcode on WordPress ... easy ... read more

Source: http://wptricks.net/how-to-detect-category-id-using-the-category-slug-in-wordpress/


Amazing Touch


Add Your Comment

Gravatar