je suis venu avec un moyen de spécifier l'alignement sur une base par la légende.
Fondamentalement, j'ai copié le shortcode légende de media.php et l'ai fait dans ma propre fonction personnalisée qui accepte un argument "captionalign". Pour l'utiliser, collez le code ci-dessous dans le fichier "function.php" de votre thème - ceci vous permettra de spécifier une option dans votre tag de légende nommé capationalign. En définissant ce paramètre sur droite, gauche ou centre, vous pouvez spécifier un alignement de texte par légende. Si vous omettez l'attribut, la légende sera définie par défaut sur l'alignement par défaut.
Un exemple utilisé:
[caption align="aligncenter" width="300" caption="My caption" captionalign="right"]
<a href="http://www.myawesomeblog.com/wp-content/uploads/2010/05/image.jpg">
<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" />
</a>
[/caption]
Et voici la fonction:
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' => '',
'align' => 'alignnone',
'width' => '',
'caption' => '',
'captionalign' => ''
), $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: ' . (10 + (int) $width) . 'px">'
. do_shortcode($content) . '<p class="wp-caption-text" style="text-align:' . $captionalign . '">' . $caption . '</p></div>';
}
espoir qui aide quelqu'un!
Essayez-vous d'aligner à droite TOUTES les légendes d'images sur votre site, ou juste une légende particulière? –
toutes les légendes d'image feraient je suppose - je suppose que vous avez un plugin à l'esprit? – rutherford