Im battling to add a description / introduction field to the top of the archive of my custom post type. I manage easy with with ACF’s option page, but I would like to do without ACF.
I have managed, halfway, but i think my code is messy…
The description/introduction does displays on the frontend, but in the admin, the textarea’s layout is not funny: I can’t get it to display full-width and some odd spaces are added once I hit save.
Please help me out 🙂
See 2x screenshots.
Is there a better way to simply add a custom field where users can add a description which will the display at the top of custom post type page;
Very much the same as one can add a description for a taxonomy.
This is my code:
//http://wpsettingsapi.jeroensormani.com/
add_action( 'admin_menu', 'tsumtour_add_admin_menu' );
add_action( 'admin_init', 'tsumtour_settings_init' );
function tsumtour_add_admin_menu( ) {
add_submenu_page( 'edit.php?post_type=tour', 'Tour', 'Intro', 'manage_options', 'tour', 'tsumtour_options_page' );
}
function tsumtour_settings_init( ) {
register_setting( 'pluginPage', 'tsumtour_settings' );
add_settings_section(
'tsumtour_pluginPage_section',
__( 'Introduction', 'tsum_tour' ),
'tsumtour_settings_section_callback',
'pluginPage'
);
add_settings_field(
'tsumtour_textarea_field_0',
__( '', 'tsum_tour' ),
'tsumtour_textarea_field_0_render',
'pluginPage',
'tsumtour_pluginPage_section'
);
}
function tsumtour_textarea_field_0_render( ) {
$options = get_option( 'tsumtour_settings' );
?>
<textarea cols="80" rows="15" name="tsumtour_settings[tsumtour_textarea_field_0]">
<?php echo $options['tsumtour_textarea_field_0']; ?>
</textarea>
<?php
}