Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Metabox snippet

class Post_Meta_Box {

	public function __construct() {

		if ( is_admin() ) {
			add_action( 'load-post.php',     array( $this, 'init_metabox' ) );
			add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
		}

	}

	public function init_metabox() {

		add_action( 'add_meta_boxes', array( $this, 'add_metabox'  )        );
		add_action( 'save_post',      array( $this, 'save_metabox' ), 10, 2 );

	}

	public function add_metabox() {

		add_meta_box(
			'post_box',
			__( 'Advanced Options', 'ez4u' ),
			array( $this, 'render_metabox' ),
			'post',
			'side',
			'high'
		);

	}

	public function render_metabox( $post ) {

		// Retrieve an existing value from the database.
		$sg_redirect_url = get_post_meta( $post->ID, 'sg_redirect_url', true );

		// Set default values.
		if( empty( $sg_redirect_url ) ) $sg_redirect_url = '';

		// Form fields.
		echo '<table class="form-table">';

		echo '	<tr>';
		echo '		<th><label for="sg_redirect_url" class="sg_redirect_url_label">' . __( 'Redirect URL', 'ez4u' ) . '</label></th>';
		echo '		<td>';
		echo '			<input type="url" id="sg_redirect_url" name="sg_redirect_url" class="sg_redirect_url_field" placeholder="' . esc_attr__( 'http://', 'ez4u' ) . '" value="' . esc_attr__( $sg_redirect_url ) . '">';
		echo '		</td>';
		echo '	</tr>';

		echo '</table>';

	}

	public function save_metabox( $post_id, $post ) {

		// Check if it's not an autosave.
		if ( wp_is_post_autosave( $post_id ) )
			return;

		// Check if it's not a revision.
		if ( wp_is_post_revision( $post_id ) )
			return;

		// Sanitize user input.
		$sg_new_redirect_url = isset( $_POST[ 'sg_redirect_url' ] ) ? sanitize_text_field( $_POST[ 'sg_redirect_url' ] ) : '';

		// Update the meta field in the database.
		update_post_meta( $post_id, 'sg_redirect_url', $sg_new_redirect_url );

	}

}

new Post_Meta_Box;