Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #249427

    Hi,
    I added the following code to have an author url field at caption of single images which I insert to the post.
    Would it be possible to add it in the single image in a gallery as well?

    add_filter("attachment_fields_to_edit", "add_image_source_url", 10, 2);
    function add_image_source_url($form_fields, $post) {
    	$form_fields["source_url"] = array(
    		"label" => __("Author name"),
    		"input" => "text",
    		"value" => get_post_meta($post->ID, "source_url", true),
                    "helps" => __("Add an author name here"),
    	);
     	return $form_fields;
    }
    
    add_filter("attachment_fields_to_save", "save_image_source_url", 10 , 2);
    function save_image_source_url($post, $attachment) {
    	if (isset($attachment['source_url']))
    		update_post_meta($post['ID'], 'source_url', esc_url($attachment['source_url']));
    	return $post;
    }
    
    add_filter('img_caption_shortcode', 'caption_shortcode_with_credits', 10, 3);
    function caption_shortcode_with_credits($empty, $attr, $content) {
    	extract(shortcode_atts(array(
    		'id'	=> '',
    		'align'	=> 'alignnone',
    		'width'	=> '',
    		'caption' => ''
    	), $attr));
    
    	// Extract attachment $post->ID
    	preg_match('/\d+/', $id, $att_id);
    	if (is_numeric($att_id[0]) && $source_url = get_post_meta($att_id[0], 'source_url', true)) {
    		$parts = parse_url($source_url);
    		//$caption .= ' ('. __('via') .' <a href="'. $source_url .'">'. $parts['host'] .'</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) . '" style="width: ' . (10 + (int) $width) . 'px">'
    		. do_shortcode($content) . '<p class="wp-caption-text">' . $caption . '</p></div>';
    }
    #249546

    Hey motylanogha!

    Thank you for using the theme!

    Unfortunately, this is beyond the scope of support as stated on support policy and is not a theme related issue. You might need to investigate the feature yourself, find a plugin or hire a freelance developer to add the feature for you. Please do visit Werkpress for further customization. You can also vote or post the feature on our Feature Requests page.

    If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries. Thank you for your understanding.

    Regards,
    Ismael

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.