Adding a YouTube Video via the Directory / Custompress Plugin

I'm trying to embed a YouTube video using a custom field. I've created the field and pasted in a YouTube URL. In the single-listing.php I've tried to add this line:

<?php echo do_shortcode('[embed]<?php echo do_shortcode('[ct id="ct_YouTube_Vi_text_d128" property="value"]'); ?>[/embed]'); ?>

That gives me a server error. Any thoughts?

  • Troy
    • Site Builder, Child of Zeus

    The field was created via custompress. I do have the box checked that allows WP and other plugins to use this field. And the embed code, within the [embed] tads is the custompress do_shortcode, embed code.

    :slight_smile:

  • Troy
    • Site Builder, Child of Zeus

    Thanks for the tip Arnold but that didn't work either. This may not be possible because of the timing of when the YouTube video is called and when the WP YouTube embed function is run...

    If you've got any other thoughts, I'd love to hear them.

  • Arnold
    • El Macho WP

    You have a good point here which is a little more wisely applicable. The custom field shortcodes should get expanded first to insure they can take part in other shortcodes like embeds etc. For example you should be able to do things like.

    [embed][ct id="ct_Video_text_f2ed" property="value"][/embed]

    right in a post and have it properly expand. Default would be to try to embed the shortcode text itself rather than the expanded shortcode because the [embed] tag comes first and starts expanding first.

    So I've made some changes to directory to reorder the priority of when shortcodes occur which lets it process properly. I've attached it to this message so give it a try.

    For your template embed just echo the above and it should work.

  • Troy
    • Site Builder, Child of Zeus

    Thanks for all your help with this!

    I downloaded and upgraded my version of the Directory plugin.

    I tried all three of these:

    [embed][ct id="ct_Video_text_f2ed" property="value"][/embed]
    
    <?php echo do_shortcode('[embed][ct id="ct_Video_text_f2ed" property="value"][/embed]'); ?>
    
    <?php echo do_shortcode('[embed]' . do_shortcode('[ct id="ct_YouTube_Vi_text_d128" property="value"]') . '[/embed]'); ?>

    All three did not work.

  • Troy
    • Site Builder, Child of Zeus

    Ha. Yeah, you were right. I was using your field id. However, that still didn't work. :slight_frown:

    Here is what I tried:

    [embed][ct id="ct_YouTube_Vi_text_d128" property="value"][/embed] 
    
    <?php echo do_shortcode('[embed][ct id="ct_YouTube_Vi_text_d128" property="value"][/embed]'); ?>
    
    <?php echo do_shortcode('[embed]' . do_shortcode('[ct id="ct_YouTube_Vi_text_d128" property="value"]') . '[/embed]'); ?>
  • Troy
    • Site Builder, Child of Zeus

    Yeah, my custom filed is working. Using just the clean embed code it renders my YouTube URL to the page.

    I also double checked the YouTube URL I'm using by pasting it into a post. It renders an embed of the video just fine.

  • Troy
    • Site Builder, Child of Zeus

    I am running the CustomPress plugin that comes with Directory, version 1.2.2.3.

    The Directory plugin is Version 2.1.1.4RC2.

    I'm running Wordpress Multisite, 3.3.2 and all of my plugins are up to date.

    I'm on a Cent OS6 LAMP, Rackspace Cloud server.

  • Troy
    • Site Builder, Child of Zeus

    I hadn't but I just did. That worked.

    But I do need it to work in the template for my site.

    My listings will be created by the users. So they will enter in their own YouTube video URL's. My template will then style that, as well as, several other fields.

    Also, I am about to leave and won't be able to work on this until Wednesday again. I appreciate all of your help today though! And for getting the Directory plugin working again!! :slight_smile:

  • Troy
    • Site Builder, Child of Zeus

    HUGE thanks to Arnold for his help with this. Here is the code that Arnold created for my Directory listing template (single-listing.php) so that a CustomPress field can be used to embed a YouTube video:

    <?php
    								$video = do_shortcode('[ct id="ct_YouTube_Vi_text_d128" property="value"]');
    								$parts = parse_url($video); //Break up the youtube url
    								if(empty($parts['query'])){
    									$vid = trim($parts['path'],'/ '); //No query string use the path to get the ID
    								} else {
    									parse_str($parts['query'], $vout); //Have a query string, use the v=ID
    									$vid = $vout['v'];
    								}
    								?>
    								<iframe width="270" height="152" src="http://www.youtube.com/embed/<?php echo $vid?>" frameborder="0" allowfullscreen></iframe>

    This is a more complicated work around because I'm using the StudioPress, Genesis Theme Framework.

    If you plan to use this you'll need to change the ct id=" to whatever your custom field is.

    Hope this helps someone else!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.