Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I came up with a way to specify alignment on a per-caption basis.</p> <p>Basically, I copied the caption shortcode from the media.php and made it into my own custom function which accepts a "captionalign" argument.</p> <p>To use, paste the below code into your theme's "function.php" file - this will allow you to specify an option in your caption tag named captionalign. By setting this to right, left, or center, you can specify a per-caption text alignment. Leaving out the attribute will have the caption default to whatever you have your default alignment as.</p> <p>An example of this in use:</p> <pre><code>[caption align="aligncenter" width="300" caption="My caption" captionalign="right"] &lt;a href="http://www.myawesomeblog.com/wp-content/uploads/2010/05/image.jpg"&gt; &lt;img title="My image" src="http://www.myawesomeblog.com/wp-content/uploads/2010/05/image.jpg-300x216.jpg" alt="My image" width="300" height="216" /&gt; &lt;/a&gt; [/caption] </code></pre> <p>And here is the function:</p> <pre><code>add_shortcode('wp_caption', 'custom_img_caption_shortcode'); add_shortcode('caption', 'custom_img_caption_shortcode'); /** * The Caption shortcode. * * Allows a plugin to replace the content that would otherwise be returned. The * filter is 'img_caption_shortcode' and passes an empty string, the attr * parameter and the content parameter values. * * The supported attributes for the shortcode are 'id', 'align', 'width', and * 'caption'. * * @since 2.6.0 * * @param array $attr Attributes attributed to the shortcode. * @param string $content Optional. Shortcode content. * @return string */ function custom_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' =&gt; '', 'align' =&gt; 'alignnone', 'width' =&gt; '', 'caption' =&gt; '', 'captionalign' =&gt; '' ), $attr)); if ( 1 &gt; (int) $width || empty($caption) ) return $content; if ( $id ) $id = 'id="' . esc_attr($id) . '" '; return '&lt;div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px"&gt;' . do_shortcode( $content ) . '&lt;p class="wp-caption-text" style="text-align:' . $captionalign . '"&gt;' . $caption . '&lt;/p&gt;&lt;/div&gt;'; } </code></pre> <p>Hope that helps someone!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload