画像を配置する際にメディアライブラリでキャプションを入力した画像のコードが
[caption ] imgタグ キャプション文字列 [/caption]
のように囲まれてしまいます。
(これだと CKEditor プラグインを使用した際、キョプションの文字列が caption ショートコード の外になってしまいます。)
CKEditorプラグインでの動作は分かりませんが、閉じタグの前に出力されていますので、’caption’ショートコードの外側には出ていません。
また、投稿の表示時にはショートコードが正常に展開されていますので、テーマがきちんと作成されていれば、表示も問題ありません。
ネット上の情報は、3.4より前(3.3.x以前)のバージョンのものだと思われます。
3.4からは現在のようなショートコードが出力されるようになったようです。
バージョンアップによる変更ですので、CKEditorプラグインで何か問題が発生しているようでしたら、プラグインの作者さんに報告して対応してもらってください。
こんにちは、フィルタを使うと、表示を自分の好みに合わせることが出来ます
テーマのfunctions.phpに 以下のコードを記述してみてください
注意:たぶん3.4からキャプションにhtmlタグが使えるようになっているので、アトリビュートで使う場合は、サニタイズしてください。
add_filter( 'img_caption_shortcode', 'textdomain_change_caption', 10, 3 );
function textdomain_change_caption( $none, $att, $content ){
var_dump($content);
var_dump($att);
return 'My_content';
}
wp-admin/includes/media.php
という部分は、見当たりませんが、同じファイルの以下の関数を探してください
/**
* 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 img_caption_shortcode($attr, $content = null) {
// New-style shortcode with the caption inside the shortcode with the link and image tags.
if ( ! isset( $attr['caption'] ) ) {
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
$content = $matches[1];
$attr['caption'] = trim( $matches[2] );
}
}
// 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: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}
add_shortcode('gallery', 'gallery_shortcode');
なので
[caption ] imgタグ キャプション文字列 [/caption] へ 1票
[caption ] imgタグ キャプション文字列 [/caption] が
3.4からはデフォルトなのですね。
CKEditorではまだ対応していないようなので、
「wp-admin/includes/media.php」を修正するようにしました。
nobita様のコードも参考させていただきます。
popup様 nobita様
ありがとうございました。