2

コードのスニペットを使用して、Wordpress がサイトのフロント エンドのキャプション画像に追加した 10 ピクセルの幅を効果的に削除しています。ただし、tinymce エディターではまだ 10px を追加しています。

<dl id="attachment_69" class="wp-caption alignleft" style="width: 310px" data-mce-style="width: 310px;">

この10pxを削除するにはどうすればよいですか? いくつかの場所で「10 +」を0に変更して、コアを変更しようとしましたが(悪い考えです、私は知っています)、運がありません。

ありがとう!

4

1 に答える 1

6

これが私たちが使用しているものです。これをテーマの functions.php に入れます。

// Override img caption shortcode to fix 10px issue.
add_filter('img_caption_shortcode', 'fix_img_caption_shortcode', 10, 3);

function fix_img_caption_shortcode($val, $attr, $content = null) {
    extract(shortcode_atts(array(
        'id'    => '',
        'align' => '',
        'width' => '',
        'caption' => ''
    ), $attr));

    if ( 1 > (int) $width || empty($caption) ) return $val;

    return '<div id="' . $id . '" class="wp-caption ' . esc_attr($align) . '" style="width: ' . (0 + (int) $width) . 'px">' . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}

これにより、10px の問題が完全に解消され、回避策が不要になります。

于 2013-02-13T17:04:06.860 に答える