Skip to content

Instantly share code, notes, and snippets.

@nandomoreirame
Last active July 20, 2020 21:56
Show Gist options
  • Save nandomoreirame/80eedaddcc9dbc69ddef1c6e5a5e642e to your computer and use it in GitHub Desktop.
Save nandomoreirame/80eedaddcc9dbc69ddef1c6e5a5e642e to your computer and use it in GitHub Desktop.
add custom metabox per page
<?php
function theme_metabox_per_page() {
global $pagenow;
if ( $pagenow == 'post.php' ) {
$page_id = ( $_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['post_ID'] ) ? $_POST['post_ID'] : $_GET['post'];
if ( $page_id ) {
$page_slug = get_post_field( 'post_name', $page_id );
if ( $page_slug == 'about-us' ) {
about_page_metabox();
}
if ( $page_slug == 'contact' ) {
contact_page_metabox();
}
}
}
}
add_action( 'init', 'theme_metabox_per_page', 1 );
function about_page_metabox() {
// setup about metabox here
}
function contact_page_metabox() {
// setup contact metabox here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment