add_meta_box (Will display only in specific page admin WordPress)


/* Add meta boxs for particular pages */

function meta_set_particular_page() {
    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
    $current_page_title = get_the_title($post_id);
    if ($current_page_title == 'home') {
        add_meta_box('Home_page', 'Home Name:', 'only_home', 'page', 'side', 'core');
    }
    if($current_page_title == 'about'){
        add_meta_box('About_page', 'About Name:', 'only_about', 'page', 'side', 'core');
    }
}
add_action('add_meta_boxes', 'meta_set_particular_page');

/* Add custom meta box for home page */

function only_home($post) {
    $home_page = esc_html(get_post_meta($post->ID, 'home_page', true));
    ?>
    <table style="width:100%;">
        <tr>
            <td style="width: 20%">Name</td>
            <td style="width: 40%">
                <input type="text" size="70" name="home_page" placeholder="Home Name" value="<?php echo $home_page; ?>">
            </td>
        </tr>
    </table>
    <?php
}

/*Add custom meta box for about page*/

function only_about($post) {
    $about_page = esc_html(get_post_meta($post->ID, 'about_page', true));
    ?>
    <table style="width:100%;">
        <tr>
            <td style="width: 20%">Name</td>
            <td style="width: 40%">
                <input type="text" size="50" name="about_page" placeholder="About Name" value="<?php echo $about_page; ?>">
            </td>
        </tr>
    </table>
    <?php
}

/*Save custom post meta values*/

function custom_metabox_fields($custom_metabox_id) {
    if (isset($_POST['home_page'])) {
        update_post_meta($custom_metabox_id, 'home_page', $_POST['home_page']);
    }
     if (isset($_POST['about_page'])) {
        update_post_meta($custom_metabox_id, 'about_page', $_POST['about_page']);
    }
}
add_action('save_post', 'custom_metabox_fields', 10, 2);

tech