Support » Plugin: Media Library Assistant » Updating decsription and alternative text for image already linked to a post

  • Resolved scubarob

    (@scubarob)


    Hi,

    after bulk editing all the images of my library I’ve discovered the values are correctly imported in new posts but not in existing posts.

    Indeed, wp is still using the alt/desc values inserted in the post. What can I do to programmatically update (not a dynamic function in function.php) the values in the post with the values of the image file?

    Thanks

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

    (@dglingren)

    Thanks for your interest in the plugin and for question. I want to make sure I understand what you would like to accomplish. It looks like you have used the Media/Assistant Bulk Edit area to update the ALT Text and Description values for your items, then used the “Add Media…” function to insert items in the body of your posts; is that correct?

    When you use “Add Media…” to insert an item in a post or page, WordPress generates content and adds it to the body of the post/page, just as if you had entered the content manually. There is no dynamic link from the post/page back to the item as there would be in a [gallery] or [mla_gallery] shortcode. Because the content is static, if you change the item later there is no built-in logic that goes back through your posts/pages to find and update the inserted values.

    This issue and similar issues have come up in several earlier topics:

    Issue with unattached images

    mla shortcode to show images of all posts of a WP category

    Can you bulk update titles AND add an incrementing number?

    Map Image Att. Tags to attached Post Tags

    How to add a number to the title of images inserted in same post?

    Changed ALT text doesn’t not reflect in published posts

    alt text reconciliation

    As discussed in those topics, I have created an “MLA Insert Fixit” example plugin to update post/page content along the lines you need. The current version of the plugin has a tool that will update ALT Text values in your posts. I have not done anything with the Description values, but if you can give me more information and some examples of what you need I can look into that. Any additional details you can provide would be helpful.

    If you want to experiment with the existing tool you can easily install the example plugin. Navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. You will see a submenu that lists all the example plugins and gives you a “one-click” action for installing them.

    Type “fixit” into the search box and click “Search Plugins”. You are looking for “MLA Insert Fixit” plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate it.

    Once that’s done, navigate to the Tools/Insert Fixit screen and scroll down to the “Copy ALT Text between Media Library items and Post/Page inserts” tool. You can click the tool to apply it to all of your posts/pages, or you can use the “First Post/Page ID” and “Last Post/Page ID” text boxes at the top of the screen to test it out on one or a few of your posts.

    I hope that gets you started on a solution for your application. I will leave this topic unresolved for now in case you have problems or further questions regarding the above suggestions.

    Hi David,

    yes I’ve used the “Add Media…” function to insert items in the body of my posts.

    I have also updated with the MLA the values of Alt Desc and Description for all the images of the library.

    In practice, I want to update in every post the codified html fields Alt Desc and Description for all the images in the library that have such fields compiled.

    It seems that your plugin can help for the Alt Desc field but not for the Description one.

    I will try with the plugin and I’ll wait for an answer about adding the functionality also for the Description field.

    Thanks for your support and compliments for the great work!!!

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the additional information and especially for the positive feedback.

    Can you post a link to one or more of the posts with embedded images you’d like to update? Adding a tool for updating the Description would require knowing exactly how the information appears in the body of the post. If a link isn’t possible you could post an example of the raw content; use the “Code Editor” in WordPress 5.x or the “Text” view of the classic editor to get something that looks like:

    [caption id="attachment_5716" align="alignleft" width="150"]<a href="http://l.mladev/this-one-ok/"><img width="150" height="150" class="size-thumbnail wp-image-5716" alt="impression pigmentaire sur papier fine art -" src="http://l.mladev/wp-content/uploads/2018/04/this-one-ok-150x150.jpg"></a> funambule sur fond de ciel orangé[/caption]
    

    Keep me posted (no pun intended).

    Hi David,

    I?ve just updated all images Alt field using your plugin!! It worked. With respect to the description field I can live without it!!!

    Thank you again for your support and your plugin.

    [ Signature deleted ]

    • This reply was modified 9 months, 3 weeks ago by Jan Dembowski.
    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the good news and positive feedback. I am happy to hear that the example plugin was helpful.

    I am marking this topic resolved, but please update it if you have any other problems or questions about updating the image inserts in your posts.

    jarjarbinks

    (@jarjarbinks)

    Hi,
    Thank you for developing this great plugin.
    I needed to update my ALT Text values as @scubarob.
    I followed your instructions and it worked on my test site when I first installed “Insert Fixit Tools”.
    Unfortunately it didn’t work in with my main website.(Both sites WP 5.0.3 installed.)

    I tried All Posts+Attachments and also with First/Last ID’s.
    In both cases, Insert Fixit Tools gives no error but it doesn’t update anything.
    Here is a screen shot
    Also “ALT from Item matched” posts/pages count is not right. It matches only a small amount of posts/attachments.
    Any suggestions?
    Thanks.
    (I saw your “No Support until 1st of March” notice. I’ll wait for your answer patiently 🙂 )

    Plugin Author David Lingren

    (@dglingren)

    @jarjarbinks

    Thanks for your update. I tried accessing your screen shot but got a “403 Forbidden” error.

    The Insert Fixit tool looks for a pattern match in the post/page content to do its work. It is possible that your content has a different format and is not matching. It would be most helpful to see the actual content, e.g., from the “code editor” version of the post/page. Can you post a link to one of the failing items or post an update with the content (enclosed in a code block)?

    Thanks for your patience and any further details you can provide.

    danieltotherescue

    (@danieltotherescue)

    @dglingren Thanks for your detailed replies. I’m having the saem issue as @jarjarbinks and @scubarob but am also receiving the message that 0 posts were updated after using the Fixit tool. Here is one such code example from the page which is not being updated with the alt text from the media library:

    <article id="MainContent">
    <h1>Hot Tubs, Pools, Billiards & Darts Since 1993!</h1>
    <img style="width: 377px; height: 275px; float: right;" src="https://alt-text-pool-and-cues.pantheonsite.io/wp-content/uploads/Pools-Cues-Pool-Table.jpg" />
    <img src="https://alt-text-pool-and-cues.pantheonsite.io/wp-content/uploads/2019/01/8_1547578498-300x169.jpg" width="300" height="169" class="alignnone size-medium wp-image-993" />

    and the “error” message received is:

    ALT from Item matched 84 posts/pages to 1 attachments and made 0 update(s) in 0 posts/pages. There were 0 error(s).

    Plugin Author David Lingren

    (@dglingren)

    @danieltotherescue – Thanks for finding this topic and posting your update with an example of the inserts that are not being updated; very helpful.

    As I wrote earlier, “The Insert Fixit tool looks for a pattern match in the post/page content to do its work.” In particular, the tool is looking for the alt= attribute to find where to add the ALT Text value to the insert. WordPress adds alt="" to its inserts when the item does not contain a value, but your examples do not have this default attribute format. In this case, the tool fails to add the attribute to the insert(s).

    As an experiment, consider adding the default alt="" attribute and re-running your test. If that solves the problem I can work on a version of the tool that adds the missing attributes to the inserts. Thanks for helping to solve this ongoing mystery!

    danieltotherescue

    (@danieltotherescue)

    @dglingren thanks for your quick reply!

    I actually found a workaround by using the Post/Page Insert Image Tag Attribute Modification tool in the Fixit Plugin with the following attributes:

    Data Source [+alt_text+] • Attribute Name alt

    This would fit my needs straightaway, but unfortunately in order to work the images seem to need the image class (e.g. class=”wp-image-788″). Most of the images on the sites I am trying to use this on do not have these classes. Is there any way to use the Post/Page Insert Image Tag Attribute Modification on such images without the appropriate image class?


    As to your above suggestion, I tested it and it works…but only for images with the class. Is there any way with existing plugin functionality to recognize all inserted media library images without the wp-image-<id#> class and add them?

    Plugin Author David Lingren

    (@dglingren)

    Thanks for the additional details and for trying the experiment I suggested. Thanks as well for identifying the issue with the tool’s use of wp-image-; good detective work!

    The MLA Insert Fixit tool was developed to process inserts and galleries generated by WordPress Media Manager features. It relies on the wp-image- and ids= literals in post/page content to efficiently match inserts and galleries back to the Media Library item ID values. The only alternative I know of would be to match the path and file name values of the items’ attached files. MLA’s “where used” reporting features use this technique and it requires so much database query activity that it is turned off by default based on complaints from users over the years.

    Can you tell me about how many posts/pages you have, and how many Media Library “image” items? Also, can you:

    1. Navigate to the Settings/Media Library Assistant General tab
    2. Scroll down to the “Where-used database access tuning” section
    3. Set the “Inserted in” option to “Enabled”, leaving the other options Disabled
    4. Scroll down to the “Table Defaults” section
    5. Set the “Entries per page” option to 50
    6. Scroll to the bottom and click “Save Changes” to record the new settings

    Then, go to the Media/Assistant admin page and see how long it takes to load the table pages. That will give you (and me) an idea if it’s practical to use the alternate method on your site(s). You can also try the “Base” option to see if performance improves. Let me know what the performance hit feels like. Thanks!

    danieltotherescue

    (@danieltotherescue)

    @dglingren I’m not sure what I was looking for as far as “table pages” to be honest, but the page loaded fine.

    I’m actually hoping to use the tool on multiple sites, each with anywhere from 20 – 150 images (varies quite a bit). But since the images were loaded in a non-uniform fashion, the majority lack the wp-image class, so I’d like to get that sorted if at all possible.

    In this test site’s case, there are about 55 images in the Media Library.

    About the recommended approach to match the path and file name values of the items’ attached files, were you suggesting that after taking the steps you laid out, how would I match and add the alt text in such a way?

    Thanks!

    Plugin Author David Lingren

    (@dglingren)

    Thank you for taking the time to try out the Where used reporting/Entries per page tests I outlined. What you were looking for is the overall time it took to load and display the Media/Assistant table of items and data values.

    I don’t think a couple of hundred images or posts/pages would cause a significant delay. Some of the sites MLA users have constructed have tens of thousands of items, which would be a problem.

    You asked about “the recommended approach to match the path and file name values“. What I am thinking about is enhancing the Insert Fixit tools to use the recommended approach to “match and add the alt text” for you. Let me work on that and post an update here when I have progress to report. Thanks for your patience in the interim.

    danieltotherescue

    (@danieltotherescue)

    Thanks for your reply @dglingren

    Since my last message, I have been trying a few things which might be of assistance in your update (or maybe not 🙂

    I tried adding this function to the end of the functions.php file for the child theme being used:

    /**
     * Add attachment ID class to images
     *
     * @param array $attr Array of attributes.
     * @param object $attachment Attachment Post object, instance of WP_Post class.
     * @return array Image attributes array.
     */
    function lwp_attachment_id_class( $attr, $attachment ) {
    
        $class_attr = isset( $attr['class'] ) ? $attr['class'] : '';
        $has_class = preg_match(
            '/wp\-image\-[0-9]+/',
            $class_attr,
            $matches
        );
    
        // Check if the image is missing the class
        if ( !$has_class ) {
            $class_attr .= sprintf( ' wp-image-%d', $attachment->ID );
            // Use ltrim to to remove leading space if necessary
            $attr['class'] = ltrim( $class_attr );
    
        }
        return $attr;
    }
    
    add_filter(
        'wp_get_attachment_image_attributes', 'lwp_attachment_id_class', 10, 2
    );

    My desired result by adding this function was to have the ID classes be added to each of the images. However this only resulted in the Media -> Assistant menu not populating.

    one extra point is that the images on the site were added in such a way that they are not categorized by date but simply in the main wp-content/uploads folder/filename.jpg format. If this is the case, would that make finding them and adding the class=”wp-image-<id#>” more difficult?

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the experimental filter and for your patience while I found the time to continue my work on this topic.

    Further testing revealed that the trouble with your example inserts has nothing to do with the missing class="wp-image-<id#>" values, which are not used in the tools you have tried. Rather, there is a defect in the MLA Insert Fixit code that prevents it from recognizing <img> tags that have attributes (such as your style= attribute) preceding the src= attribute. Thank you for alerting me to this defect and I regret the delay in finding and fixing it.

    I have uploaded a new MLA Development Version dated 20190520 that contains the fix required for your application. You can find step-by-step instructions for using the Development Version in this earlier topic:

    PHP Warning on media upload with Polylang

    Once the Development Version is installed you must update the example plugin to the latest version, 1.11. To update the example plugin, navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. Type “fixit” in the text box and click “Search Plugins” to filter the table.
    You are looking for the “MLA Insert Fixit” example plugin. Find that plugin and hover over the title in the left-most column. Click the “Update” (or “Install”) rollover action, then go to the WordPress Plugins/Installed Plugins submenu and verify or activate the example plugin as you would any other plugin.

    Once the updates are installed you can use the “Add Attribute” or “Replace Attribute” tool in the plugin’s “Post/Page Insert Image Tag Attribute Modification” section to insert or update your alt= attributes.

    It would be great if you can give the updated version a try and let me know how it works for you. Thanks for your help!

Viewing 15 replies - 1 through 15 (of 31 total)
  • You must be logged in to reply to this topic.