Created
August 2, 2018 16:09
-
-
Save marcelo2605/804c29762947bb6b6ca04036409e05a7 to your computer and use it in GitHub Desktop.
Replace <p> by <figure> around images and make tables responsive using table-responsive Bootstrap class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Replace <p> by <figure> around images and make tables responsive using table-responsive Bootstrap class | |
*/ | |
add_filter( 'the_content', function($content) { | |
$content = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<figure class="content-image">$1</figure>', $content); | |
// Run only if is a singular post page | |
if (is_singular()) { | |
$content = preg_replace("/(<table(?s).*<\/table>)/i", "<div class='table-responsive'>$1</div>", $content); | |
} | |
return $content; | |
}, 30 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment