ThemeShaper Forums » Thematic

[closed]

Filter Image Caption to Add Title

(3 posts)
  • Started 8 years ago by wlanni
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. wlanni
    Member

    Hello,

    I'm trying to filter the caption html to add the title. I can't find the caption function that matches the output I'm getting -- I'm seeing <dl> tags, and the function I'm finding in WordPress' code uses <div> and <p> tags.

    Basically, I just want to alter the default caption behavior with a function in my childtheme functions.php so that the title of the image is added within an tag before the caption content is added.

    I found this, but I can't make it alter my captions. Not sure what is going on:
    http://hitchhackerguide.com/2011/02/12/img_caption_shortcode/

    Has anyone successfully altered the caption code? Thanks!

    Posted 8 years ago #
  2. wlanni
    Member

    OK, looks like Page.ly's multi-edit is allowing the <dl> tags seen in the editor to come through, rather than having the caption filter get applied. GRRRR.

    anyone work with Multi-Edit and turn that off by chance?

    Posted 8 years ago #
  3. what the heck is page.ly? and how does it relate to thematic?

    i've been toying w/ the gallery shortcode (b/c galleries suck royally) and taking a look at the code you've linked to, the key will be that you have the attachment's id. from there you can just do a classic get_the_title($id) to get the title, b/c in the database wp treats attachments almost the same as it treats posts.

    try changing:

    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>';

    to:

    $title = ($id) ? '<strong>' . get_the_title($id) . ' </strong> ' : '';
    $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">' .$title . $caption . '</p></div>';

    totally untested, so ymmv

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.