Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

logo imaginet

logo for imaginet

class Custom_Meta_Box_logo {

	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(
			'logo',
			__( 'logo', 'text_domain' ),
			array( $this, 'render_metabox' ),
			'post',
			'advanced',
			'default'
		);

	}

	public function render_metabox( $post ) {

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

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

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

		echo '	<tr>';
		echo '		<th><label for="case_logo_field" class="case_logo_field_label">' . __( 'Logo Field', 'text_domain' ) . '</label></th>';
		echo '		<td>';
		echo '			<input type="url" id="case_logo_field" name="case_logo_field" class="case_logo_field_field" placeholder="' . esc_attr__( 'URL of Logo', 'text_domain' ) . '" value="' . esc_attr( $case_logo_field ) . '">';
		echo '			<p class="description">' . __( 'Save logo in media library and add URL', 'text_domain' ) . '</p>';
		echo '		</td>';
		echo '	</tr>';

		echo '</table>';

	}

	public function save_metabox( $post_id, $post ) {

		// Sanitize user input.
		$case_new_logo_field = isset( $_POST[ 'case_logo_field' ] ) ? esc_url( $_POST[ 'case_logo_field' ] ) : '';

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

	}

}

new Custom_Meta_Box_logo;