0
votes

I'am recently updated my old (3.0.1 version) wordpress blog witch have many posts with images inside. Also my blog have a script that finds all images in page content and replace them with image carousel. All works ok with old posts, but when I create a new post, carousel don't work. I noticed that the new wordpress version of the code is displayed in another way. On this carousel my script output does not work.

Is there a way to make so that shortcode is not changed. Such as a was in the old version.

old wordpress version shortcode:

[caption id="attachment_27534" align="alignnone" width="450" caption="Caption text"]<a href="image.jpg"><img class="size-full wp-image-27534" title="" src="gailius.jpg" alt="" width="450" height="370" /></a>[/caption]

new version changed this shortcode to

[caption id="attachment_27534" align="alignnone" width="450"]<a href="image.jpg"><img class="size-full wp-image-27534" title="" src="image.jpg" alt="" width="450" height="370" /></a>Caption text[/caption]

EDIT:

I found function that generate shortcode

function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {

    if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
        return $html;

    $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';

    if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
        return $html;

    $width = $matches[1];

    $caption = str_replace( array("\r\n", "\r"), "\n", $caption);
    $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );

    // Convert any remaining line breaks to <br>.
    $caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption );

    $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
    if ( empty($align) )
        $align = 'none';

    $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';

    return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
}

how i can modify this part from my functions.php?

$shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';

i am replaced all that function

add_filter( 'image_add_caption', 'my_image_add_caption');

function my_image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {

but nothing changed

1

1 Answers

0
votes

Please try the following:

remove_filter( 'image_send_to_editor', 'image_add_caption', 20);
add_filter( 'image_send_to_editor', 'my_image_add_caption', 10, 8 );

function my_image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
 // Your source
}