0

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']);
  }
}
2
  • 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, 2011 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, 2011 at 22:07

1 Answer 1

1

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']);
}
}
1
  • 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, 2011 at 0:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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