@@ -1329,22 +1329,27 @@ protected function render()
13291329 foreach ($ posts as $ post ) {
13301330 $ post_title = get_the_title ($ post ->ID );
13311331 $ dom = new DOMDocument ();
1332- if ($ settings ['remove_title ' ]=='on ' ){
1333- if (!empty ($ post ->post_content )) {
1334- @$ dom ->loadHTML ($ post ->post_content ); // Suppress warnings due to invalid HTML
1335- $ elements = $ dom ->getElementsByTagName ('h2 ' );
1336-
1337- // Loop through h2 elements and remove them
1338- foreach ($ elements as $ element ) {
1339- $ element ->parentNode ->removeChild ($ element );
1340- }
1341-
1342- // Save the modified content back to the variable
1343- $ post ->post_content = $ dom ->saveHTML ();
1332+ libxml_use_internal_errors (true ) AND libxml_clear_errors ();
1333+ if ($ settings ['remove_title ' ] == 'on ' ) {
1334+ if (!empty ($ post ->post_content )) {
1335+ // Set the charset to UTF-8
1336+ $ dom ->recover = true ;
1337+ $ dom ->strictErrorChecking = false ;
1338+ $ dom ->substituteEntities = false ;
1339+ $ dom ->loadHTML ('<?xml encoding="UTF-8"> ' . $ post ->post_content );
1340+ $ elements = $ dom ->getElementsByTagName ('h2 ' );
1341+
1342+ // Loop through h2 elements and remove them
1343+ foreach ($ elements as $ element ) {
1344+ $ element ->parentNode ->removeChild ($ element );
1345+ }
1346+ $ dom ->encoding = 'UTF-8 ' ;
1347+ $ post ->post_content = $ dom ->saveHTML ();
1348+ }
13441349 }
1345- }
1350+
13461351 if (wp_is_mobile ()) {
1347- $ post_content = wp_trim_words ($ post ->post_content , $ wordPc );
1352+ $ post_content = wp_trim_words ($ post ->post_content , $ wordMobile );
13481353
13491354 }
13501355 else {
0 commit comments