Get URL from shortcode tag

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