Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: How To Set Extracted OCR Text To Image Thumbnail Alt Instead Of...

Discussion in 'Misc WordPress Requests' started by Susan Walker, Dec 3, 2017.

  1. Susan Walker

    Guest

    Reply To: How To Set Extracted OCR Text To Image Thumbnail Alt Instead Of Custom Field…, by Susan Walker

    Hi there,

    I found where the OCR text is being inserted into the database, but there’s no filter or action hook that will let you modify this action directly.

    What you could do is to write a WP Cron job to periodically — how often depends on how quickly you need the info and the volume of files you’re handling — to turn the inserted text into the alt text.

    Basically, the cron would execute a SQL query to find all the records in the wp_postmeta table where meta_key = ‘ocr_text’ and change the meta_key to ‘_wp_attachment_image_alt’, which is the name of the field the alt text is stored in. Some things you might want to have safety checks for are whether alt text is already set (in which case you’d end up with multiple alt text values for an image, which will create problems) and a check that the text isn’t too long for the field type.

    If you could get the developer to add an action hook to the AnalyzeImage($image_id) function, right after: the line

    add_post_meta( $image_id, ‘ocr_text’, $ocr_text, true );

    you wouldn’t need to do this as a cron. You could write a function to change the meta_key value and add it to execute immediately after the ocr_text is inserted into the database.

    This is a broad outline rather than a step-by-step how-to, but if you google WP Cron and WP Query, you’ll find additional details.

    Reply To: How To Set Extracted OCR Text To Image Thumbnail Alt Instead Of Custom Field…
     
    #1

Share This Page

Web Hosting