Created
November 20, 2014 14:23
-
-
Save TiSiE/b7c29d5d6e76d085b88b to your computer and use it in GitHub Desktop.
Change wordpress shortcode pattern to allow single and enclosed version of a tag in one post/page.
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
<?php | |
// For WP 4.0 | |
// In file wp-includes/shortcodes.php line 228 and following, | |
// replace the whole return (or comment out the original code) with this line: | |
// | |
// (I know it's ugly, but it works. | |
// Basically we just replaced this part: | |
// --> '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag | |
// with: | |
// --> '\\[(?:(?!\\/\\2\\]|\\2))' | |
// ^^ ^^ | |
// Add grouping ^^ | |
// Not an opening tag with the same name (\\2 is the backreference to the matched tag.) | |
// ) | |
// | |
return '\\[(\\[?)('.$tagregexp.')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?:(?!\\/\\2\\]|\\2))[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment