Tagged: custom_class=, enfold, polylang
-
AuthorPosts
-
December 10, 2025 at 11:01 am #1492347
Hi all,
We have been using Enfold with Polylang for around a year. It has worked well to translate pages from English into German and then Spanish. However it has recently been causing issues whereby the frontend layout was broken. After some investigation, it seems that during the translation process, code is inserted ‘custom_class=’ or even ‘custom_class’ in the section and column elements. This therefore stops the execution of the page rendering and requires a manual cleanup of layout elements. I note that if an element has already been assigned an ID or class, this doesn’t happen.
I have tried the following to filter the outputs, but that hasn’t worked.
Any ideas of what else I can look into, or why this might be happening?
// Prevent Polylang from modifying Enfold shortcodes during duplication
add_filter(‘pll_copy_post_metas’, ‘preserve_enfold_alb_data’, 10, 3);
function preserve_enfold_alb_data($metas, $sync, $from) {
// Remove _aviaLayoutBuilder_active from auto-sync to force manual handling
$metas = array_diff($metas, array(‘_aviaLayoutBuilder_active’));
return $metas;
}// Clean up malformed custom_class parameters in shortcodes
add_filter(‘the_content’, ‘fix_polylang_enfold_shortcodes’, 1);
function fix_polylang_enfold_shortcodes($content) {
// Remove empty custom_class parameters from sections and columns
$content = preg_replace(‘/custom_class=[\'”]{2}/’, ”, $content);
$content = preg_replace(‘/custom_class=[\'”][\s]*[\'”]/’, ”, $content);
return $content;
}// Clean up malformed HTML output
add_filter(‘the_content’, ‘remove_custom_class_id_from_html’, 999);
function remove_custom_class_id_from_html($content) {
// Remove id=”custom_class=” (malformed with extra equals)
$content = preg_replace(‘/\s+id=[“\’]custom_class=[“\’]?/i’, ‘ ‘, $content);// Remove id=”custom_class” (literal value only)
$content = preg_replace(‘/\s+id=[“\’]custom_class[“\’]/i’, ‘ ‘, $content);return $content;
}`December 11, 2025 at 8:48 am #1492386Hey philipe,
Thank you for the inquiry.
The custom_class is a valid element parameter, so you don’t need to remove it. Are you adding custom html or shortcodes to the page? It’s possible that these custom shortcodes or embedded content are causing the issue. If you can create a test page and provide the login details in the private field, we’ll take a closer look.
Best regards,
IsmaelDecember 11, 2025 at 10:39 am #1492404thank you, I have sent details below in private content.
December 12, 2025 at 8:32 am #1492454Hi,
Thank you for the login info.
The Appearance > Theme File Editor is not accessible, so we’re not able to check if there are modifications that might be contributing to the issue. Please enable the file editor or post the S/FTP details in the private field so we can check the issue further.
Best regards,
IsmaelDecember 12, 2025 at 9:10 am #1492457This reply has been marked as private.December 15, 2025 at 7:50 am #1492512Hi,
Thank you for the info.
We just noticed that the site contains a very old version of the theme (6.0.6). Please download the latest version (7.1.3) from your Themeforest account, then try to update the theme manually via FTP. Please check the documentation below for more info.
— https://kriesi.at/documentation/enfold/theme-update/#update-via-ftp
The upgrade should fix the issue with the fold/unfold feature and the rest of the layout issues in the builder.
Best regards,
IsmaelDecember 15, 2025 at 11:22 am #1492527Thank you Ismael. How strange it was on an older version as I use the Theme update function. I have manually re-uploaded to the latest version and the same problem exists.
December 16, 2025 at 8:45 am #1492552Hi,
Thank you for the info.
We are not yet sure why custom_class is being added to the ID field, so we manually removed it from the affected elements. We also added the following code to the functions.php file to filter out the custom_class value from the ID attribute.
add_filter( 'avf_template_builder_content', 'avf_template_builder_content_mod', 10, 1 ); function avf_template_builder_content_mod( $content ) { $content = preg_replace( '/\s+id="custom_class=?"\s*/', ' ', $content ); return $content; }Please make sure to purge the cache before checking the page.
Best regards,
IsmaelDecember 16, 2025 at 11:36 am #1492558Thank you Ismael for looking into this. It is certainly a mystery as to why this custom_class is being added.
I have checked your changes and unfortunately when moving this function to live (and flushing the cache) the issue remains and the pages appear broken. So I don’t think this is filtering. The page you prepared was down to manually removing the custom_class in every page element.
Can you suggest any further ways we can look into this, as obviously having to go through every page element to remove custom_class in the ID is not practical going forward. Any thoughts you have are appreciated…?Many thanks
December 17, 2025 at 8:25 am #1492596Hi,
Thanks for following up.
The filter was working correctly on the staging site the last time we checked and removes the custom_class from the ID attribute. Is it possible to access the live site? We tried the same login info but it is not working in the live site.
Best regards,
IsmaelDecember 17, 2025 at 12:21 pm #1492613Thanks Ismael,
You said that you manually cleaned up the code, so when I added it to the live site, I was seeing the same issues as before.
I am now just testing the following, which appears to be working, but did break the nav builder when I first ran it, so filtered this so it would only work on pages and posts.
I will update as to if it works fully.
Thanks
/** * ============================================================================ * POLYLANG + ENFOLD CUSTOM_CLASS ISSUE FIXES * ============================================================================ * * Problem: When Polylang duplicates/translates pages, it incorrectly converts * custom_class attributes into id="custom_class" or id="custom_class=" in HTML output. * * Solution: Multiple filters at different points in the translation/save process * to catch and fix the issue wherever it occurs. */ /** * Solution 1: Fix content after Polylang processes it (Primary Fix) * This runs after Polylang has translated the content but before it's saved * * CRITICAL FIX: Handles unclosed custom_class=' attributes that break Enfold's parser * IMPORTANT: Excludes nav_menu_item to prevent menu structure issues */ add_filter('pll_filter_translated_post', 'fix_polylang_custom_class_issue', 20, 4); function fix_polylang_custom_class_issue($tr_post, $source_post, $target_language, $data) { if (!$tr_post instanceof WP_Post) { return $tr_post; } // Exclude menu items - they don't contain Enfold shortcodes if ($tr_post->post_type === 'nav_menu_item') { return $tr_post; } $content = $tr_post->post_content; $original_content = $content; // Fix 1: Remove malformed id="custom_class=" or id="custom_class" in HTML $content = preg_replace( '/\s+id=["\']custom_class(?:=["\'])?/i', '', $content ); // Fix 2: Fix unclosed custom_class=' attributes (THE MAIN ISSUE) // Pattern: custom_class=' followed by space, closing bracket, or end of shortcode // Replace with custom_class='' (properly closed empty attribute) $before_fix2 = $content; $content = preg_replace( "/custom_class='(?=\s|'|])/i", "custom_class=''", $content ); $fix2_count = substr_count($before_fix2, "custom_class='") - substr_count($content, "custom_class='"); // Fix 3: Also handle custom_class=" (double quotes, unclosed) $before_fix3 = $content; $content = preg_replace( '/custom_class="(?=\s|"|])/i', 'custom_class=""', $content ); $fix3_count = substr_count($before_fix3, 'custom_class="') - substr_count($content, 'custom_class="'); // Fix 4: Remove custom_class='' or custom_class="" if they appear as standalone (no value) // This cleans up empty attributes that might cause issues $before_fix4 = $content; $content = preg_replace( "/\s+custom_class=['\"]{2}/i", '', $content ); $fix4_count = (substr_count($before_fix4, "custom_class=''") + substr_count($before_fix4, 'custom_class=""')) - (substr_count($content, "custom_class=''") + substr_count($content, 'custom_class=""')); // Fix 5: Fix in shortcode attributes - sometimes custom_class becomes id in shortcodes $before_fix5 = $content; $content = preg_replace( '/\[([a-z_]+)([^\]]*?)\s+id=["\']custom_class(?:=["\'])?([^\]]*?)\]/i', '[$1$2$3]', $content ); $fix5_count = substr_count($before_fix5, 'id="custom_class') - substr_count($content, 'id="custom_class'); // Debug logging (only if WP_DEBUG is enabled) if (defined('WP_DEBUG') && WP_DEBUG && $content !== $original_content) { error_log(sprintf( '[POLYLANG FIX] Post ID %d: Fixed %d unclosed custom_class=\' attributes, %d unclosed custom_class=", %d empty custom_class, %d id="custom_class" issues', $tr_post->ID, $fix2_count, $fix3_count, $fix4_count, $fix5_count )); } $tr_post->post_content = $content; return $tr_post; } /** * Solution 2: Clean content when post is saved (Backup Fix) * This catches the issue at save time as a safety net * * CRITICAL: Fixes unclosed custom_class=' attributes * IMPORTANT: Excludes nav_menu_item to prevent menu structure issues */ add_filter('wp_insert_post_data', 'clean_custom_class_on_save', 10, 2); function clean_custom_class_on_save($data, $postarr) { // Exclude menu items - they don't contain Enfold shortcodes and menu structure is in postmeta if (!isset($data['post_type']) || $data['post_type'] === 'nav_menu_item') { return $data; } if (!isset($data['post_content'])) { return $data; } $content = $data['post_content']; // Fix 1: Remove id="custom_class=" or id="custom_class" from content $content = preg_replace( '/\s+id=["\']custom_class(?:=["\'])?/i', '', $content ); // Fix 2: Fix unclosed custom_class=' attributes $content = preg_replace( "/custom_class='(?=\s|'|])/i", "custom_class=''", $content ); // Fix 3: Fix unclosed custom_class=" (double quotes) $content = preg_replace( '/custom_class="(?=\s|"|])/i', 'custom_class=""', $content ); // Fix 4: Remove empty custom_class='' or custom_class="" attributes $content = preg_replace( "/\s+custom_class=['\"]{2}/i", '', $content ); $data['post_content'] = $content; return $data; } /** * Solution 3: Clean content right after Polylang duplication * This runs immediately after Polylang creates a sync post * * CRITICAL: Fixes unclosed custom_class=' attributes that break Enfold * IMPORTANT: Excludes nav_menu_item to prevent menu structure issues */ add_action('pll_created_sync_post', 'clean_enfold_content_after_duplication', 5, 4); function clean_enfold_content_after_duplication($post_id, $tr_id, $lang, $strategy) { $post = get_post($tr_id); if (!$post) { return; } // Exclude menu items - they don't contain Enfold shortcodes if ($post->post_type === 'nav_menu_item') { return; } $content = $post->post_content; $original = $content; // Fix 1: Remove malformed id="custom_class" issues $content = preg_replace('/\s+id=["\']custom_class(?:=["\'])?/i', '', $content); // Fix 2: Fix unclosed custom_class=' attributes (THE MAIN ISSUE) // Replace custom_class=' (unclosed) with custom_class='' (properly closed) $before_fix2 = $content; $content = preg_replace( "/custom_class='(?=\s|'|])/i", "custom_class=''", $content ); $fix2_count = substr_count($before_fix2, "custom_class='") - substr_count($content, "custom_class='"); // Fix 3: Fix unclosed custom_class=" (double quotes) $before_fix3 = $content; $content = preg_replace( '/custom_class="(?=\s|"|])/i', 'custom_class=""', $content ); $fix3_count = substr_count($before_fix3, 'custom_class="') - substr_count($content, 'custom_class="'); // Fix 4: Remove empty custom_class='' or custom_class="" attributes entirely // Enfold doesn't need empty custom_class attributes $before_fix4 = $content; $content = preg_replace( "/\s+custom_class=['\"]{2}/i", '', $content ); $fix4_count = (substr_count($before_fix4, "custom_class=''") + substr_count($before_fix4, 'custom_class=""')) - (substr_count($content, "custom_class=''") + substr_count($content, 'custom_class=""')); // Fix 5: Ensure custom_class attributes with values are properly formatted $content = preg_replace_callback( '/\[([a-z_]+)([^\]]*?)\s+custom_class=([^\s"\']+)([^\]]*?)\]/i', function($matches) { // Ensure custom_class has quotes if missing $value = trim($matches[3]); if (!preg_match('/^["\'].*["\']$/', $value)) { $value = '"' . esc_attr($value) . '"'; } return '[' . $matches[1] . $matches[2] . ' custom_class=' . $value . $matches[4] . ']'; }, $content ); // Debug logging (only if WP_DEBUG is enabled) if (defined('WP_DEBUG') && WP_DEBUG && $content !== $original) { error_log(sprintf( '[POLYLANG FIX] Post ID %d (from %d): Fixed %d unclosed custom_class=\', %d unclosed custom_class=", %d empty custom_class attributes', $tr_id, $post_id, $fix2_count, $fix3_count, $fix4_count )); } if ($content !== $original) { wp_update_post(array( 'ID' => $tr_id, 'post_content' => $content )); } } /** * Solution 4: Clean content on frontend display (Final Safety Net) * This ensures broken content doesn't display even if it got into the database */ add_filter('the_content', 'remove_custom_class_id_from_html', 999); function remove_custom_class_id_from_html($content) { // Remove id="custom_class=" (malformed with extra equals) $content = preg_replace('/\s+id=["\']custom_class=["\']?/i', ' ', $content); // Remove id="custom_class" (literal value only) $content = preg_replace('/\s+id=["\']custom_class["\']/i', ' ', $content); return $content; }December 30, 2025 at 3:39 am #1493580 -
AuthorPosts
- You must be logged in to reply to this topic.
