• Hello everyone !

    I’m currently customizing the captions for a client, and I have two separate problems that I can’t seem to find a fix for.
    #1 : I’m bypassing the standard WP caption shortcode in order to display the description of the media alongside the actual caption. I do that with the following filter :

    add_filter('img_caption_shortcode', 'ffap_img_caption_shortcode', 10, 3);
    function ffap_img_caption_shortcode($val, $attr, $content = null) {
    
      extract(shortcode_atts(array(
        'id'    => '',
        'align' => 'alignnone',
        'width' => '',
        'caption' => ''
      ), $attr));
    
      if ( 1 > (int) $width || empty($caption) ) return $content;
    
      // Grab ID to query post_content [description] field for image
      preg_match('/([\d]+)/', $id, $matches);
    
      // get the description html
      $description_html = '';
      if ( $matches[0] ) {
        global $wpdb;
        $custom_description = $wpdb->get_row("SELECT post_content FROM $wpdb->posts WHERE ID = {$matches[0]};");
        if ($custom_description->post_content) {
          $description_html = "<p class=\"caption--description\">{$custom_description->post_content}</p>";
        }
      }
    
      // get the caption html and other fragments for the attachement
      $caption_html = "<p class=\"wp-caption-text\">{$caption}</p>";
      $id_html      = esc_attr($id);
      $align_html 	= esc_attr($align);
      $style_html 	= sprintf('width: %s px', 10 + (int)$width);
      $content_html = do_shortcode($content);
    
      return "<figure id=\"{$id_html}\" class=\"caption {$align_html}\">{$content_html}<figcaption>{$caption_html}{$description_html}</figcaption></figure>";
    }

    That works perfectly fine, on the front end. However in the TinyMCE in the backend, the caption displays as usual. My client would get confused and so I would like to be able to see that description with the caption in the back end also. Any way that’s possible ?

    And then problem #2. When editing an image in the backend’s visual editor using this button :
    https://www.dropbox.com/s/rms3e7q240o0ovn/Capture%20d%27%C3%A9cran%202015-10-21%2014.40.05.png?dl=0 The opening pop up window does not allow for a quick modification of that description, only the caption. Any way I could add the description to that window ?

    Thanks for any help !

The topic ‘Captions in TinyMCE’ is closed to new replies.