Reputation: 41
I have a shortcode ( outputURL ) that is used to output a value into a URL. The value is retrieved from a shortcode ( valueURL ). The valueURL output is text wrapped in a div:
<div class="">textForURL</div>
I need only the textForURL value, excluding the div tags. Thus far, I have only been able to output the div tags and text but not the clean version of just text.
Here is my shortcode function:
function ouputURL(){
$content = '[valueURL id="5"]';
$clean = preg_replace("#<div.*?>.*?</div>#", "", $content);
echo do_shortcode( $clean );
}
add_shortcode('output', 'ouputURL');
I researched and was able to put this together but I am unsure as to whether I am heading in the right direction of executing it correctly. Any help to achieve my goal will be appreciated.
EDIT:
This is to further clarify my problem.
I am using a WordPress plugin which manages all embedded video URLs within a post;
As a feature, the plugin allows for a single video id ( i.e. vid=X23dw34 ) to be added through it's admin page which is viewed in a playlist prior to viewing the primary video;
I want to use an ad rotator plugin to manage multiple video id's and serve a single video id based upon the ad serving parameters and called by a shortcode ( i.e. [valueURL id="5"] );
The ad rotator plugin wraps a DIV around the video id:
<div class="">X23dw34</div>
"...video.com/embed/<div class="">X23dw34</div>..."
"...video.com/embed/X23dw34..."
I am not sure if my limited understanding of shortcode and parsing is the issue or if my ultimate objective can not be handled by a simple function.
Please let me know if you require further information.
EDIT 2:
Here is the entire iframe, I removed extra tabs that to format it correctly:
<iframe width="100%" height="459" src="http://www.youtube.com/embed/oiE5qs8opqo?rel=0&autoplay=0&showinfo=0&controls=0&cc_load_policy=0&modestbranding=1&iv_load_policy=3&wmode=transparent&version=3&autohide=1" frameborder="0" allowfullscreen="true" allownetworking="internal"></iframe>
Upvotes: 0
Views: 332
Reputation: 3848
I didn't fully understand but this should hopefully put you on track:
add_shortcode('output', 'ouputURL');
function ouputURL ( $atts ) {
if(!isset($atts['id']))
return;
$valueURL = do_shortcode("[valueURL id={$atts['id']}]");
preg_match("#<div.*?>(.*?)</div>#", $valueURL, $matches);
if(!isset($matches[1]))
return;
return $matches[1]; // the ID
}
So if inside the content of a post/page you put [output id=5]
it will retrieve the result of [valueURL id=5]
, find the content of the div
tag and return it to be printed on the page.
You can modify it to return something more than just the ID.
Upvotes: 0