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
- How to manually fix the WordPress gallery code using PHP in functions.php?
- Encode text string being appended as query to URL [closed]
- Correct regex for wp_embed_register_handler
- Display a text message if the shortcode is not found?
- How to return a string that has a variable inside in a shortcode?
- Passing a shortcode attribute to a sub-function
- Changing the HTML Of the content
- post meta value as shortcode parameter
- How to protect own PHP code from WordPress updates
- Adding Image Count to Multigallery
- How to add Shortcode (font awesome) in widget title?
- WordPress Wysiwyg Content not being displayed
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- Nested shortCode functions in the functions.php file
- Placing the_content inside shortcode not working
- get_page_by_title with an apostrophe in variable
- Autogenerate shortcodes from an array of strings
- How can I get content inside one shortcode to another shortcode?
- is_page “range” for if statement?
- How can I generate random numbers inside my shortcodes on each implementation?
- Use WP_Query in shortcode
- Custom Theme, Custom shortcode not working
- Different loop output every x posts in custom post type
- Showing a different gallery in a seperate post
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- Calculating a large number of MYSQL queries as customshort codes, slow
- WordPress Shortcodes.. printf is outputting a random number… Can’t figure out WHY?
- Applying A Category to Existing Posts Where Page Title Matches Regex
- How can I dynamically update the class in my shortcode?
- Displaying recent posts on static page with template-part via shortcode
- How to Reference/Echo Variable from Another PHP Function
- Replace shortcode in substring
- Embedding PHP in shortcode $content
- Shortcode with PHP issue “Undefined index”
- Excecuting php function in shortcode
- Returning data instead of echoing/printing
- List taxonomy term slugs within shortcode (do_shortcode)
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- ::before on open/close function [closed]
- Is There A Way To Make Theme Files Accept Shortcodes?
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- do_action(), iFrame Gets Displayed Despite Password Protection [closed]
- Using Shortcode to Grab Archive Listing, Separate by Year
- calling a custom field value inside functions.php
- Using ob_start and ob_get_clean with wordpress shortcode
- List all blogs, but exclude the main site
- How to add no follow to specific links?
- Shortcode to pull posts
- Extract links from content
- Get the_content surrounded by instead of
- PHP code inside Shortcode
- Help Fallback (thumbnail)
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- Action Hook Inside WordPress Plugin Shortcode
- How can I include the user id inside of a shortcode php output?
- PHP Helper Class to create shortcodes
- help with custom shortcode that stopped working
- Change Spaces to Dashes?
- how to get sentence values from wordpress shortcode parameter?
- Updating Metadata with Shortcode
- using shortcodes inside gravity forms
- Create shortcode for metabox gallery
- couldnt show short code atts in category
- How can I edit the final HTML structure of the whole web page
- I am having an issue with this shortcode plugin.. Warning: Illegal string offset ‘title’
- Advanced Custom Forms PHP formatting for do_shortcode
- overwrite wordpress gallery with custom gallery shortcode
- How to use Contact Form 7 shortcode value in a page?
- How to bind each “the_content” elements to a custom variables
- How to wrap pattern-matches from the_content in [wiki]-shortcode tags
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- CPT in a shortcode
- Show products per shortcode
- Open/closed function [closed]
- What is wrong with this shortcode? to include external php file in WordPress posts
- Need to Echo A Url path to show on a wordpress page
- WordPress Shortcode based on other shortcode
- Wrapping shortcode content in a span or link
- Is there a way to have chunks of a page’s content expire?
- Formatting Shortcode to Display in Visual Mode
- How to pass parameter that ends up being part of a class name with wordpress shortcode
- How to have Function of a plugin using global vars into a shortcode?
- Overwriting a Shortcode
- Where to place PHP for shortcodes
- Whats wrong with my code? Need To add String to shortcode? [closed]
- A next page function with shortcode?
- Excerpt all post content Content Same Size without word cutting off
- using a shortcode in a hyperlink
- Display total count of products in orders of a specific order status
- Gutenberg – render_callback does not pass ToggleControl value on frontend
- HTTP 500 Error after Creating Shortcode
- How call WordPress shortcode inside function file
- How to execute a shortcode within a custom field?