3
votes

To Begin, I'm using this plugin

http://wordpress.org/extend/plugins/my-youtube-playlist/ & this theme, www.press75.com/themes/on-demand/this-is-a-sample-video-post-4/

My intention is to have the youtube playlist displayed in the gray area on the theme, where there is currently only 1 video displayed. my intention was to use the Youtube Code embed field of the theme as the place where i could put the plugin shortcode and therefore have the plugin create the playlist needed for the post. However I've been unable to get the plugin to execute the shortcode once it is NOT placed in the content area of the post.

The theme creates a video container Div (the gray area for the video) once either a video link is posted or video embed code is entered into the relevant field of the theme.

I've tried the following

  • Hardcoding the [myyoutubeplaylist LO3n67BQvh0, WGOohBytKTU, iwY5o2fsG7Y, PyKNxUThW4E, 1cX4t5-YpHQ, SJ183htYl-8, eWwoHPrrJYY, bja2ttzGOFM] into the single post php file to see if the plug would pick it up. No Luck. It simply output the shortcode to the screen

  • Hardcoding <?php echo do_shortcode('[myyoutubeplaylist LO3n67BQvh0, WGOohBytKTU, iwY5o2fsG7Y, PyKNxUThW4E, 1cX4t5-YpHQ, SJ183htYl-8, eWwoHPrrJYY, bja2ttzGOFM]'); ?> to see if it would pick it up. No Luck. It simply outputs the shortcode to the screen.

  • Having the template dump the shortcode parameters into the following:
    <?php echo do_shortcode( get_video($post->ID); ?>. No Luck. It simply outputs the shortcode to the screen

  • Repeating all the above outside of the video container div created by the theme

I'm fresh out of idea's, so any and all help would be GREATLY appreciated

5
Would love to see a solution for this too. - marcamillion

5 Answers

1
votes

Put this in your functions.php file:

add_filter('widget_text', 'do_shortcode');

Then use the shortcode in your sidebar as you would in the main content area.

0
votes

or try this one - TubePress

you can code it into your theme in several ways, and you can easily edit it's appearance with CSS...

edit: how to embedd tubepress shortcode outside post/page (it looks to me like some of this comes with pro version tho)

0
votes

I know this question is fairly old now but as none of the answers have resolved it I'll see about providing some insight on it.

If you're trying to place a shortcode from your content in to another area in your theme you'll need to register a filter and add the call where you want the shortcode to be run. Let's say that we would like a shortcode with a similar functionality as what you're trying to do in your question - but I'm going to start it at the beginning for anyone who's interested.

We'll start by registering a new shortcode to output a video from a direct YouTube link such as this https://www.youtube.com/watch?v=eh7lp9umG2I so that users don't have to do any parsing by hand (we really only need the last parameter).

After this we'll need to register a filter. In this case since we're wanting to take this video out of the content and put it somewhere else we'll be applying a filter on 'the_content'.

Next we'll create a function to make sure we grab a copy of the shortcode before the filter removes it - just keeping everything DRY.

Lastly we simply need to output the video.

function your_shortcode_handler($atts)
{
    $url = $atts['video'];

    if (isset($url))
    {
        $type = 'application/x-shockwave-flash';
        $url  = str_replace("watch?v=", 'v/', $url);

        $obj  = "<object data='$url' type='$type'><param name='src' value='$url' /></object>"

        return $obj;
    }
}

add_shortcode('your_shortcode_name', 'your_shortcode_handler');

function your_shortcode_filter($content)
{
    $pattern = "/\[your_shortcode_name(.*?)\]/";

    $content = preg_replace($pattern, '', $content);

    return $content;
}

add_filter('the_content', 'your_shortcode_filter');

function stealFromContent($content)
{
    $pattern = "/\[your_shortcode_name(.*?)\]/";
    $match = null;

    preg_match($pattern, $content, $match);

    if (is_array($match) and $match[0] != '')
    {
        return $match[0];
    }

    return '';
}

//somewhere in the template you're wanting to add the video to
//BEFORE the_content is called.
$youtube_video = stealFromContent();

//then

echo $youtube_video; //wherever you want it.

Now to answer the author's question. The select type of individual who wrote this plugin isn't using a shortcode. He is regexing over the_content similar to what I'm doing above and then passing those values to a javascript library.

When do_shortcode is called it parses all of the shortcodes and ignores the non shortcode values. A good hint was the fact that the shortcode you're providing simply isn't a shortcode - [word space word space] is invalid.

The source file for reference.

-1
votes
<?php echo myYoutubePlaylist('[myyoutubeplaylist WnY59mDJ1gg, bKwQ_zeRwEs]'); ?>