Last active
July 20, 2020 21:56
-
-
Save nandomoreirame/80eedaddcc9dbc69ddef1c6e5a5e642e to your computer and use it in GitHub Desktop.
add custom metabox per page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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