• Resolved ckweb1230

    (@ckweb1230)


    Hi. Thanks for this terrific plugin. I’ve got it working fine for the credits associated with featured images, using the handy “the_media_credit()” function, to output only the credit in my template.

    I’d like to have similar control over the credit that appears under an image inserted into a post. By default, the plugin inserts the credit just underneath the image, but I’d like the credit text to be appended to the end of the caption.

    Can you point me to a way I can add a filter that will accomplish this? Basically, I want to customize the output of the “media_credit_shortcode()” function found inside the plugin’s media-credit.php file.

    Thanks.

    https://wordpress.org/plugins/media-credit/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author pepe

    (@pputzer)

    It is possible (I do exactly that on my blog), but you have to filter img_caption_shortcode and insert the credit yourself. You can use this sample code to parse the [media-credit] from the $content encapsulated by the [caption] shortcode:

    $credit_content = '';
    $pattern = get_shortcode_regex();
    preg_match('/'.$pattern.'/s', $content, $matches);
    
    // Check if media-credit shortcode is used inside the caption
    if ( isset($matches[2]) && is_array($matches) && $matches[2] == 'media-credit') {
    	// media-credit shortcode is being used
    	// remove media-credit shortcode from content
    	$content = str_replace( $matches['0'], $matches['5'], $content );
    
    	// parse media-credit attributes
    	$attr = shortcode_atts(array('id' => -1, 'name' => ''), shortcode_parse_atts($matches['3']));
    
    	if ($attr['id'] && $attr['id'] != -1) {
    		$credit_content = get_media_credit_html_by_user_ID($attr['id']);
    	} else {
    		$credit_content = $attr['name'];
    	}
    }
    Thread Starter ckweb1230

    (@ckweb1230)

    Thanks so much, pepe. Your sample code worked like a charm, and I’ve got things appearing just as I want. I really appreciate your super-speedy help.

    Plugin Author pepe

    (@pputzer)

    Glad it worked out! I have been thinking about providing a setting for this (in conjunction with HTML5-style captions), but filtering captions is probably too theme-specific …

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Control placement of media credit in posts’ is closed to new replies.