Title: HTML Exception Error
Last modified: May 3, 2025

---

# HTML Exception Error

 *  Resolved [Websites Built For You](https://wordpress.org/support/users/websitesbuiltforyou/)
 * (@websitesbuiltforyou)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/html-exception-error/)
 * Just wanted to report a small issue I’ve had. Basically, the plugin was throwing
   an error as below:
 * [03-May-2025 08:16:36 UTC] PHP Fatal error: Uncaught ValueError: DOMDocument::
   loadHTML(): Argument #1 ($source) must not be empty in /var/www/html/wp-content/
   plugins/fix-alt-text/inc/Scan.php:532
   Stack trace:#0 /var/www/html/wp-content/
   plugins/fix-alt-text/inc/Scan.php(532): DOMDocument->loadHTML()#1 /var/www/html/
   wp-content/plugins/fix-alt-text/inc/Scan.php(273): FixAltText\Scan::get_from_html()#
   2 /var/www/html/wp-content/plugins/fix-alt-text/library/_helpers-library/inc/
   Scan_Process_Library.php(779): FixAltText\Scan::scan_post()#3 /var/www/html/wp-
   content/plugins/fix-alt-text/library/_helpers-library/inc/Scan_Process_Library.
   php(462): FixAltText\HelpersLibrary\Scan_Process_Library->process()#4 /var/www/
   html/wp-content/plugins/fix-alt-text/library/_helpers-library/inc/Scan_Process_Library.
   php(1536): FixAltText\HelpersLibrary\Scan_Process_Library->handle()#5 /var/www/
   html/wp-includes/class-wp-hook.php(324): FixAltText\HelpersLibrary\Scan_Process_Library-
   >maybe_handle()#6 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->
   apply_filters()#7 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action()#
   8 /var/www/html/wp-admin/admin-ajax.php(192): do_action()#9 {main} thrown in /
   var/www/html/wp-content/plugins/fix-alt-text/inc/Scan.php on line 532
 * This was causing the progress to get stuck. Turns out the issue was due to effectively
   empty html (so for example ” ” (single space) not being detected on some post
   types. I think this is because the site it’s installed on uses ACF extensively
   and doesn’t always have main content.
   I fixed it by adding a catch to the block
   as below:
 * public static function get_from_html( string $html, array $args = [] ): array{
 *     ```wp-block-code
           // Must have something to scan
           if ( empty( $args ) ) {
               return [];
           }
   
           // Require HTML
           if ( empty( $html ) ) {
               return [];
           }
   
           // Empty array to hold all links to return
           $all_references = [];
   
           // Create DOM structure so we can reliably grab all img tags
           $dom = new DOMDocument();
   
           // Silence warnings
           libxml_use_internal_errors( true );
   
           // Ensure we are using UTF-8 Encoding
           $html = htmlspecialchars_decode( htmlentities( $html, ENT_COMPAT, 'utf-8', false ) );
   
           try {
               // Load the URL's content into the DOM
               $dom->loadHTML( $html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED );
   
               $images = $dom->getElementsByTagName( 'img' );
               $image_index = 0;
   
               // Ensure we have default values
               $args['from_post_id'] = $args['from_post_id'] ?? 0;
               $args['from_post_type'] = $args['from_post_type'] ?? '';
               $args['from_where'] = $args['from_where'] ?? '';
               $args['from_where_key'] = $args['from_where_key'] ?? '';
   
               // Loop through each <img> tag in the dom and add it to the link array
               foreach ( $images as $img ) {
   
                   // Inherit base details from args
                   $ref = $args;
   
                   // Fixing legacy code from breaking Gutenburg Editor
                   $img->removeAttribute( 'id' );
   
                   $ref['image_index'] = $image_index;
                   $ref['image_url'] = $img->getAttribute( 'src' );
                   $ref['image_alt_text'] = $img->getAttribute( 'alt' );
   
                   $all_references[] = new Reference( $ref );
   
                   ++ $image_index;
   
               }
           } catch ( \Throwable $e ) {
               error_log( print_r( $html, 1 ) );
               // Deliberately empty.
           }
   
           // Done silencing errors
           libxml_clear_errors();
   
           //Return the links
           return $all_references;
       }
       ```
   
 * Anyway, I know its not really a support issue but wanted to report it so you 
   could hopefully include in the next release of what is a great little plugin!
   I’m going to leave a 5 star review for you now!
   Thanks for all the hard work 
   guys!Steve

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Steven Ayers](https://wordpress.org/support/users/stevenayers63/)
 * (@stevenayers63)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/html-exception-error/#post-18450452)
 * [@websitesbuiltforyou](https://wordpress.org/support/users/websitesbuiltforyou/),
 * Thank you for the bug report and fix! I will implement, test, and release something
   later today. 🙂
 * I’ll update this thread and close it once the new version has been released.
 * -Steven
 *  Plugin Author [Steven Ayers](https://wordpress.org/support/users/stevenayers63/)
 * (@stevenayers63)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/html-exception-error/#post-18451388)
 * [@websitesbuiltforyou](https://wordpress.org/support/users/websitesbuiltforyou/),
 * I just released version 1.9.1 to patch the bug you reported. Please update the
   plugin and confirm that it solves the issue on your end.
 * Once confirmed, I’ll close this support ticket.
 * -Steven
 *  Plugin Author [Steven Ayers](https://wordpress.org/support/users/stevenayers63/)
 * (@stevenayers63)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/html-exception-error/#post-18451419)
 * [@websitesbuiltforyou](https://wordpress.org/support/users/websitesbuiltforyou/),
   
   Also, this bug affected another plugin called [WhereUsed](https://wordpress.org/plugins/where-used/).
   The fix will be released in version 1.5.0 of WhereUsed. Unfortunately, it will
   take a little longer for that release as it is a big release.
 * -Steven
 *  Thread Starter [Websites Built For You](https://wordpress.org/support/users/websitesbuiltforyou/)
 * (@websitesbuiltforyou)
 * [11 months ago](https://wordpress.org/support/topic/html-exception-error/#post-18459297)
 * Hi Steven, sorry it took me a while but I can confirm that I’ve installed the
   update and its working great.
   Thanks again and keep up the great work!CheersSteve

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘HTML Exception Error’ is closed to new replies.

 * ![](https://ps.w.org/fix-alt-text/assets/icon.svg?rev=2674473)
 * [Fix Alt Text](https://wordpress.org/plugins/fix-alt-text/)
 * [Support Threads](https://wordpress.org/support/plugin/fix-alt-text/)
 * [Active Topics](https://wordpress.org/support/plugin/fix-alt-text/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/fix-alt-text/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/fix-alt-text/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Websites Built For You](https://wordpress.org/support/users/websitesbuiltforyou/)
 * Last activity: [11 months ago](https://wordpress.org/support/topic/html-exception-error/#post-18459297)
 * Status: resolved