There’s no need to use regex for this. WordPress has a Shortcode API to do this work for you.
That codex page includes one of my favorite codex code snippets:
function bartag_func( $atts ) {
extract( shortcode_atts( array(
'foo' => 'something',
'bar' => 'something else',
), $atts ) );
...
Right at the start of the function registering the shortcode it does the following:
- take the user-submitted shortcodes and fill them in with defaults if they aren’t provided
- takes the
$atts
argument and turn each valued into a variable (e.g.$foo
,$bar
, etc.)- For you, you’d get
$mp4
and$poster
- For you, you’d get
Related Posts:
- Wrap First Character after in a tag
- Showing content from one page on another
- Only first shortcode gets executed
- Create a WordPress shortcode using PHP [duplicate]
- Including Custom fields within the_content
- How to Create custom block for displaying information in content section which act like shortcode
- What do ++ and *+ mean?
- Matching a space in regex
- How to manually fix the WordPress gallery code using PHP in functions.php?
- Return HTML Template Page with PHP Function
- Encode text string being appended as query to URL [closed]
- Insert Custom HTML After Shortcode
- How can i remove all html tags from get_the_content()?
- How do I use Shortcodes inside of HTML tags?
- Is there a way to parse shortcodes in PHP?
- Correct regex for wp_embed_register_handler
- Shortcode to insert
- Shortcode putting html such as
- Display sorting options dropdown when using WooCommerce product category shortcode
- Retrieve multiple values passed to a single attribute in a shortcode
- WordPress Shortcode and Dynamic CSS
- ob_get_clean returns empty string, ob_get_flush outputs string
- Display a text message if the shortcode is not found?
- Export User Info to CSV from Front End
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- Shortcode created to check language not works
- How to return a string that has a variable inside in a shortcode?
- Run shortcode at certain resolution
- Using Echo in ShortCode – Stuck
- Passing a shortcode attribute to a sub-function
- Changing the HTML Of the content
- How to create shortcodes that pull custom field data from general settings
- post meta value as shortcode parameter
- append PHP function to the_content
- How to protect own PHP code from WordPress updates
- Add/echo div with Analytics-Code to function in functions.php
- Creating a WordPress shortcode
- Multiple do_shortcode($content) within one shortcode
- Adding Image Count to Multigallery
- the_title() & the_content() are retrieving Post details inside a Page, after calling a shortcode
- Get list of shortcodes from content
- Audio tags around Mp3 URL in content
- How do I hardcode a WordPress shortcode into my theme?
- Loading page template into shortcode
- My shortcode is showing up twice
- How to add Shortcode (font awesome) in widget title?
- has_shortcode() – how to detect nested shortcode
- WordPress Wysiwyg Content not being displayed
- sql query to put quotes around numbers in img tag
- How to return multiples lines in a shortcode?
- Go to / Scroll to Password Field on WordPress Posts After Submit With Message(s)
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- How can I default to all WordPress roles when parameter is not included in shortcode?
- WordPress menu deletes when trying to add a hook
- PHP contact form returns warning in text widget [closed]
- How to find the output of contact form 7 shortcode? [closed]
- Extremely slow pageload for long post when using the_content?
- Wrap each shortcode in array to div
- How do i get (unique) page name?
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- Can A Shortcode Get HTML/Text From Content And Return It Twice With Added HTML?
- Recent post display using shortcode
- Browser title script ignoring is_page /else conditional [closed]
- How do I turn a shortcode into PHP code?
- Nested shortCode functions in the functions.php file
- Placing the_content inside shortcode not working
- Put php variable in shortcode
- Output 2 items within the Loop
- get_page_by_title with an apostrophe in variable
- Need to turn this php into WP shortcode
- Making Quote Plugin more efficient
- Autogenerate shortcodes from an array of strings
- How to limit the content coming from wordpress shortcodes?
- How to return a foreach inside a shortcode
- Placing raw HTML inside a WordPress shortcode
- How do I add text in a shortcode?
- How to Insert Shortcodes into Theme?
- How can I get content inside one shortcode to another shortcode?
- Template part inside shortcode, unexpected reult
- Shortcode Inside Class Not Working
- custom shortcode will not display the wrapped content
- Shortcode content output but not in correct place
- How to call function at the bottom of post using plugin?
- is_page “range” for if statement?
- How can I generate random numbers inside my shortcodes on each implementation?
- PHP code inside shortcodes
- Use WP_Query in shortcode
- Shortcode API: How to get name that matched shortcode RegEx?
- Shortcode content filter?
- Create shortcodes within foreach loop (using array)
- Custom Theme, Custom shortcode not working
- Trigger popup in a php if/else statement
- Append HTML Using Shortcode
- Why is file_get_contents returning page source?
- Plugin CSS not enqueing
- Output Buffering – Everything between wp_head and wp_print_footer_scripts?
- How do I Add HTML to the_excerpt() & the_content() Output?
- Different loop output every x posts in custom post type
- How to output a PHP file values by shortcode?
- Showing a different gallery in a seperate post