Wrap table tag around div tag
wordpress
Solution
You should try with question mark after wildcard ( zero or more spaces ) and "s" flag after "i" flag. First change should help your regular expression function to differentiate between variations of table tag with or without spaces and attributes. Second should include newlines in regex search:
~<table.*?</table>~is
and full code would be
function tekst_wrapper($content) {
return preg_replace_callback('~<table.*?</table>~is', function($match) {
return '<div>' . $match[0] . '</div>';
}, $content);
}
add_filter('the_content', 'tekst_wrapper');
Problem
I tried to use this snippet of code to wrap a div tag around each table tag within post content, but I don't know why it doesn't work: ``` function tekst_wrapper($content) { return preg_replace_callback('~<table.*</table>~i', function($match) { return '<div>' . $match[0] . '</div>'; }, $content); } add_filter('the_content', 'tekst_wrapper'); ```