Skip to content

Instantly share code, notes, and snippets.

@TiSiE
Created November 20, 2014 14:23
Show Gist options
  • Save TiSiE/b7c29d5d6e76d085b88b to your computer and use it in GitHub Desktop.
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.
<?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