WordPress custom field or meta box to add data to footer

I have a custom theme which has a footer.php file, which contains my footer.

This footer contains two YouTube videos which I have currently hardcoded into the theme template file footer.php.

Read More

What I would like to do is control which videos are displayed in the footer from the WP Dashboard.

I am not sure what is the best way to approach this.

This is my code in footer.php

<div class="row">
  <div class="col-md-6">
    <iframe width="240" height="170" src="//www.youtube.com/embed/abcdefg" frameborder="0" allowfullscreen></iframe>
  </div><!-- /.6 -->

  <div class="col-md-6">
    <iframe width="240" height="170" src="//www.youtube.com/embed/hijklm" frameborder="0" allowfullscreen></iframe>
  </div><!-- /.6 -->
</div><!-- /.row -->

I was thinking of replacing the video URL with some variable somehow that is editable via my dashboard.

An approach I was looking at was http://mor10.com/simple-video-embedding-with-custom-fields-in-wordpress-youtube/comment-page-1/#comment-1253601

But this seems to be based around your page being a post.

Thanks

Related posts

Leave a Reply

1 comment

  1. I dont suggest using Custom Fields or Meta boxes for this. As custom fields and meta boxes are used mostly per post/page basis. Basically it will only output the data entered if you are on that specific post or page.

    I’d suggest widgets, here’s something you can use:

    Register your new widget areas, add this to your functions.php file of your theme:

    function footer_widget() {
    
        register_sidebar( array(
            'name' => 'Footer Area 1',
            'id' => 'footer_widget',
            'before_widget' => '<div>',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="rounded">',
            'after_title' => '</h2>',
        ) );
    }
    add_action( 'widgets_init', 'footer_widget' );
    
    function footer_widget_2() {
    
        register_sidebar( array(
            'name' => 'Footer Area 2',
            'id' => 'footer_widget_2',
            'before_widget' => '<div>',
            'after_widget' => '</div>',
            'before_title' => '<h2 class="rounded">',
            'after_title' => '</h2>',
        ) );
       }
    add_action( 'widgets_init', 'footer_widget_2' );
    

    You can output it in your theme by editing your footer as:

    <div class="row">
      <div class="col-md-6">
        <?php if ( dynamic_sidebar('footer_widget') ) : else : endif; ?>
      </div><!-- /.6 -->
    
      <div class="col-md-6">
        <?php if ( dynamic_sidebar('footer_widget_2') ) : else : endif; ?>
      </div><!-- /.6 -->
    </div><!-- /.row -->
    

    Then you can just add the text widget to your Footer Area 1 and Footer Area 2 Widget areas in WordPress Dashboard -> Appearance -> Widgets, and insert their <iframe>