Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a page with a simple YouTube embed. I would like the client to be able to easily switch the video id from the dashboard without having to edit any templates.

Something like this: <iframe width="576" height="324" src="http://www.youtube.com/embed/<?=$video_id ?>"></iframe>

So I'm trying to insert a metabox in the home page of the respective custom post type (see below) but am not sure how to go about it.

enter image description here

Is something like this possible? If not, is there a way to insert a metabox into the 'home' dashboard page of the WordPress dashboard? I'm open to any suggestions as well. Thank you. - Update -

This is what I currently have in my functions.php:

// YouTube Metabox
add_action('wp_dashboard_setup', 'custom_dashbox');

function custom_dashbox() {
  global $wp_meta_boxes;
  wp_add_dashboard_widget('widget_slug','Featured Video', 'widget_display','widget_submission');
}

function widget_display() {
  echo '<label><small>YouTube ID</small></label><br /><br /><input type="text" name="youtube_id" /><br/><br />
  <input type="submit" name="submit_youtube" />';
}

function widget_submit() {
  //Do what you need to do with your youtube id possibly:
  if (get_option('youtubeid'))
  {
    update_option('youtubeid',$_POST['youtube_id']);
  }
  else {
    add_option('youtubeid',$_POST['youtube_id']);
  }
}
share|improve this question
    
Just to clarify a bit... Do you want to allow the client to add a different video ID for each "Furniture" post? Or do all your furniture posts use a single template that has a video embedded and the client chooses a single ID for all furniture posts? –  Jared Cobb Jul 11 '11 at 21:44
    
Yes, I should have clarified this. No, not a different id for each post. There will only be one video in total at the top of the page. It'll be sort of a featured video. The client will only be featuring one video at a time. –  jwp Jul 11 '11 at 22:07
add comment

1 Answer

Try something like this. I haven't actually done this yet, it is something I was looking into, so please let me know how it goes.

add_action('wp_dashboard_setup', 'custom_dashbox');

    function custom_dashbox() {
    global $wp_meta_boxes;

    wp_add_dashboard_widget('widget_slug','Widget Name', 'widget_display','widget_submission');
    }

    function widget_display() {
    echo '<input type="text" name="youtube_id" /><br/>
<input type="submit" name="submit_youtube" />';
    }

function widget_submit() {
//Do what you need to do with your youtube id possibly:
if (get_option('youtubeid'))
{
update_option('youtubeid',$_POST['youtube_id']);
}
else {
add_option('youtubeid',$_POST['youtube_id']);
}
}
share|improve this answer
    
I have tried playing around with this and the widget shows up fine in my dashboard but I can't get it to save. I am not too skilled with php so I feel I may be missing something obvious. I've updated the original post with what I have right now in my functions.php. –  jwp Jul 14 '11 at 0:54
add comment

Your Answer

 
discard

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.