你说的东西叫做a custom meta box. 它们可用于保存特定于帖子的设置和数据。您可以在的帮助下创建自己的元框add_meta_box() 作用
这里有一个简单的例子。这将转到您(孩子)的主题functions.php 文件或者,如果希望使代码主题独立,则创建a custom plugin 对于下面的代码。该示例适用于经典编辑器和块编辑器。
// Register metabox only for "post" post type
add_action(\'add_meta_boxes_post\', \'my_prefix_register_my_custom_metabox\', 10, 1);
function my_prefix_register_my_custom_metabox( $post ) {
    add_meta_box(
        \'my-metabox\', // id
        esc_html__( \'My Meta Box\', \'textdomain\' ), // title
        \'my_prefix_render_my_custom_metabox\', // callback
        \'post\', // screen - typically post type
        \'side\', // context - normal, side, advanced
        \'high\', // priority - high, low
        array() // optional callback args
    );
}
// Callback function that add_meta_box uses to render the contents of the metabox
function my_prefix_render_my_custom_metabox( $post, $callback_args ) {
    $checked = get_post_meta( $post->ID, \'_my_checkbox_value\', true );
    wp_nonce_field( \'my_custom_metabox_nonce_action_\' . $post->ID, \'my_custom_metabox_nonce\' );
    ?>
    <label>
        <input type="checkbox" name="_my_checkbox_value" value="1" <?php checked( $checked, 1); ?>>
        <span><?php esc_html_e( \'Display disclaimer\', \'textdomain\' ); ?></span>
    </label>
    <?php
}
// Callback for saving the metabox form fields when the post is saved
// Executes only when saving "post" post type
add_action( \'save_post_post\', \'my_prefix_save_my_custom_metabox\', 10, 3 );
function my_prefix_save_my_custom_metabox( $post_id, $post, $update ) {
    if ( ! current_user_can( \'edit_post\', $post_id ) ) {
        return;
    }
    if (
        wp_is_post_autosave( $post_id ) ||
        wp_is_post_revision( $post_id )
    ) {
        return;
    }
    if (
        empty( $_POST[\'my_custom_metabox_nonce\'] ) ||
        ! wp_verify_nonce( $_POST[\'my_custom_metabox_nonce\'], \'my_custom_metabox_nonce_action_\' . $post_id )
    ) {
        return;
    }
    if ( isset( $_POST[\'_my_checkbox_value\'] ) ) {
        update_post_meta( $post_id, \'_my_checkbox_value\', 1 );
    } else {
        delete_post_meta( $post_id, \'_my_checkbox_value\', 1 );
    }
}
 您还可以向同一文件中添加一个助手函数,该函数负责显示免责声明消息。
function my_prefix_display_disclaimer() {
    if (
        is_single() &&
        get_post_meta( get_the_ID(), \'_my_checkbox_value\', true )
    ) {
        ?>
        <aside class="disclaimer">
            <p>This is a disclaimer.</p>
        </aside>
        <?php
    }
}
 然后,您可以在某个(子)主题模板文件中直接使用helper函数。
<?php my_prefix_display_disclaimer(); ?>
 或者将其挂接到主题可能提供的动作挂钩中。
// in functions.php or custom plugin file
add_action( \'some_theme_template_action_hook\', \'my_prefix_display_disclaimer\' );