Skip to content

Instantly share code, notes, and snippets.

@jasonreposa
Created October 26, 2011 14:02

Revisions

  1. jasonreposa revised this gist Oct 26, 2011. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // Originally built for http://www.mybanktracker.com/bank-news/
    function mbt_img_caption_shortcode($val, $attr, $content = null) {
    extract(shortcode_atts(array(
    'id' => '',
  2. jasonreposa created this gist Oct 26, 2011.
    31 changes: 31 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    function mbt_img_caption_shortcode($val, $attr, $content = null) {
    extract(shortcode_atts(array(
    'id' => '',
    'align' => 'alignnone',
    'width' => '',
    'caption' => ''
    ), $attr));

    // if it contains a pipe character, we know it's ours
    if (strpos($caption, '|') === FALSE) {
    return;
    }

    $tokens = explode('|', $caption);
    $caption = array_shift($tokens);
    $href = implode('|', $tokens);
    if (!empty($href)) {
    $caption .= ' <a href="' . $href . '" rel="nofollow">source</a>';
    }

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

    if ( $id ) $id = 'id="' . esc_attr($id) . '" ';

    return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '">'
    . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
    }

    // what is 10, 3 for?
    add_filter('img_caption_shortcode', 'mbt_img_caption_shortcode', 10, 3);