WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running a wordpress site and I need the correct regex syntax to get a URL from some shortcode that is returned inside the_content().

When I use the_content(), it will return something like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam nulla enim, euismod ut pharetra nec, commodo a augue. Etiam sit amet nibh mauris, eu ornare purus. Vestibulum sed sem enim, sit amet congue leo. 

[video mp4=<<insert video url here>> poster=<<insert imgae placeholder url>>]

How can I get just the video mp4 URL?

share|improve this question

migrated from stackoverflow.com Nov 17 '12 at 5:33

This question came from our site for professional and enthusiast programmers.

This isn't a WordPress question, IMHO. If reworded, it could be though. – Dan Jan 16 '13 at 0:09

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
share|improve this answer

You can use substring and strpos to extract this

$spos = strpos($getContent,"mp4=");
if($spos) {
$spos = $spos+4;//4 for four charactars mp4= 
$epos = strpos($getContent,' ',$spos) - $spos;
$url = substr($getContent,$spos,$epos);
echo $url;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.