Support » Plugin: Media Library Assistant » Image caption to text in post?

  • Resolved brandjuh

    (@brandjuh)


    Hello and for who it’s going to celebrate, have a nice Xmas. (Better early then late ;-))

    Before I going to explain everything I explain what I want:
    Since I am press photographer I need to deliver my photo’s as fast as possible to the customer. Almost everything is done from Lightroom I did not update my website because it was to much work, I must edit and export the images, go to wordpress, make gallery, add tags etc etc etc. It just took me to much time and the site went out-of-date that lead to less costumers on not press related business.
    So I decided to take action on wordpress and make it automatic, with the groundrule that if I publish the photos from lightroom to wordpress the post is generated and posted, I do not have to do anything in wordpress.

    Thats where I found WP/LR sync to transfer my photos to lightroom with all the needed information. Title for title, keywords for the tags and the caption I want to use as description in my post. Its also making a shortcode to my post.

    But I have a huge struggle to get the information to the post, wp/lr is not doing it so I did take a look to other plugins. That is where I found wp-photo2content this works like a charm with the keyword but does not post the caption to the description because the post has already some text. The developer don’t want to edit this because he is using it for his own.
    So I am left with the fact that keywords are added as tags but caption is not added as description in the post.

    The theme I use is Extra from Elegant theme but the support they give is not that elegant since the it takes 24+ hours for each reaction you get in the ticket and for me the most time it ends with “We do not support this or that or we are focused on other elements now.

    Because of that I tried to get some php experts that could change the code but so far no luck with it. That brings me to MLA and I am struggling with it and I do not know if its my bad or the plugin is not able to do it.

    Is it possible that the plugin hets the image caption and place it above the every other text in a post? If yes, what are the common settings?

    In the IPCT/EXIF tab I have set the caption to 2#120 but what value I need to put into the template?

    I am busy with this for more than a week and just getting a little bit tired and messing everything up now. Hope you can help me!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your question and for all the details you have added about your application and your goal; very helpful.

    As you have discovered, plugins like WP/LR Synch and MLA can help you extract IPTC, EXIF and XMP metadata from your image files and transfer it to fields like Title, Caption, Description and ALT Text in the Media Library item created for the image. You can also assign taxonomy terms and custom field values in the item. MLA will also update or add to the image metadata (image_meta) array associated with the item. These functions are provided in the Settings/Media Library Assistant IPTC/EXIF tab, as you have found.

    Your application and goal are somewhat different. You want to create a WordPress post and fill the post’s Description field with values extracted from the item assigned as the post’s Featured Image. MLA does not have any direct functions to modify post information based on its Featured Image or items attached to the post. You could add an ‘[mla_gallery]’ shortcode to you post to display the information, but this would be a manual step that you do not want to add to your workflow.

    You could use the hooks provided by MLA to accomplish your goal. There are already two MLA example plugins that do something similar: “Random Featured Image” and “MLA Dynamic References Example”. You would have to modify the PHP code in either example to get what you want.

    You have already found another code example/plugin that is very close to a solution; the wp-photo2content plugin you mentioned. I found a blog post and the code here:

    How to fill a WordPress post content and tags based on IPTC keywords of featured image

    GitHub petermolnar/wp-photo2content

    As you wrote, this plugin is close to what you want but will not modify the post content if it is not empty. This is most likely a simple way to prevent destroying the existing content or adding a duplicate copy of the caption to the content each time the post is altered. I believe the simplest solution for your application is to modify the wp-photo2content code. Here is a replacement for the content_from_photo function in that plugin that should work for you:

    
    function content_from_photo ( &$post, $thid ) {
    	$meta = wp_get_attachment_metadata( $thid );
    	
    	// Make sure a caption exists
    	if ( empty( $meta['image_meta']['caption'] ) ) {
    		return;
    	}
    	
    	$caption = $meta['image_meta']['caption'];
    	$content = $post->post_content;
    
    	// See if the caption is already there
    	if ( 0 === strpos( $content, $caption ) ) {
    		return;
    	}
    	
    	// Add the caption to the content
    	$content = $caption . "\n" . $content;
    	replace_content ( $post, $content );
    }
    

    The above function will add the Featured Image caption to the post content unless it finds the caption already there.

    Note that this solution uses the image_meta caption value, not the Caption field from the Featured Image item. This means that any changes you make to the caption after adding the item will not be copied into the post. It’s easy to change that if it is a problem.

    I hope you can copy the new function into your copy of the wp-photo2content plugin. If you would like a copy by e-mail, you can send me your contact information from the Contact Us page at our web site:

    Fair Trade Judaica/Contact Us

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions. Thanks for your interest in MLA.

    Hey David,

    Sorry for the late answer, it was a little busy the last day.
    Thanks for the help you give me on a plugin you don’t have made!

    I did edit the PHP file within wordpress, I have replaced the content_from_photo in it.
    Made a test upload and it looks like it is not working. Even the keywords are not working now, maybe I made a typo or other mistake while editing.

    http://www.roelsmitsfotografie.nl/file/prive/screenschots/screenshot21-12-2016-18u57m40s.png

    for the record I did not make a change in MLA, so nothing is mapped, do I need a specified thing?

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update; I regret the trouble you are having with my suggested fix. The code you posted looks good, but I have had trouble in the past with the WordPress plugin editor.

    If you can send me your contact information I will send you a complete copy of the plugin with the modifications. You can deactivate and delete the copy you have and then upload and install the replacement.

    If that doesn’t work I can investigate further.

    Hello David,

    I have send you a message from the site you give me earlier.

    Thanks 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Image caption to text in post?’ is closed to new replies.