Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Bshvil post input metabox

class Bshvil_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(
			'postMetabox',
			__( 'Advanced Options', 'bshvil' ),
			array( $this, 'bshvilMetabox' ),
			'post',
			'side',
			'high'
		);

	}

	public function bshvilMetabox( $post ) {

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

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

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

		echo '	<tr>';
		echo '		<th><label for="cdkPostSubtitle" class="cdkPostSubtitle_label">' . __( 'Title', 'bshvil' ) . '</label></th>';
		echo '		<td>';
		echo '			<input type="text" id="cdkPostSubtitle" name="cdkPostSubtitle" class="cdkPostSubtitle_field" placeholder="' . esc_attr__( '', 'bshvil' ) . '" value="' . esc_attr__( $cdkPostSubtitle ) . '">';
		echo '		</td>';
		echo '	</tr>';

		echo '</table>';

	}

	public function save_metabox( $post_id, $post ) {

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

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

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

	}

}

new Bshvil_Meta_Box;