Differenze tra le versioni di "WordPress:Sezione di una pagina di amministrazione"

 
(Una versione intermedia di uno stesso utente non è mostrata)
Riga 9: Riga 9:
  
 
function my_settings_init() {
 
function my_settings_init() {
 +
 
     add_settings_section(
 
     add_settings_section(
 
         'sample_page_setting_section',
 
         'sample_page_setting_section',
Riga 15: Riga 16:
 
         'sample-page'
 
         'sample-page'
 
     );
 
     );
 +
 +
add_settings_field(
 +
  'my_setting_field',
 +
  __( 'My custom setting field', 'my-textdomain' ),
 +
  'my_setting_markup',
 +
  'sample-page',
 +
  'sample_page_setting_section'
 +
);
 +
 +
register_setting( 'sample-page', 'my_custom_settings_options' );
 
}
 
}
  
 
function my_setting_section_callback_function() {
 
function my_setting_section_callback_function() {
 
     echo '<p>Intro text for our settings section</p>';
 
     echo '<p>Intro text for our settings section</p>';
 +
}
 +
 +
function my_setting_markup() {
 +
    ?>
 +
    <label for="my_setting_field"><?php _e( 'My Input', 'my-textdomain' ); ?></label>
 +
    <input type="text" id="my_setting_field" name="my_setting_field">
 +
    <?php
 
}
 
}
 
</pre>
 
</pre>
 +
fonte: https://themes.artbees.net/blog/custom-setting-page-in-wordpress/

Versione attuale delle 20:32, 5 set 2021

← ritorno

Sdvsbdrvuydvbuiy5g.png
add_action( 'admin_init', 'my_settings_init' );

function my_settings_init() {

    add_settings_section(
        'sample_page_setting_section',
        __( 'Custom settings', 'my-textdomain' ),
        'my_setting_section_callback_function',
        'sample-page'
    );

	add_settings_field(
	   'my_setting_field',
	   __( 'My custom setting field', 'my-textdomain' ),
	   'my_setting_markup',
	   'sample-page',
	   'sample_page_setting_section'
	);

	register_setting( 'sample-page', 'my_custom_settings_options' );
}

function my_setting_section_callback_function() {
    echo '<p>Intro text for our settings section</p>';
}

function my_setting_markup() {
    ?>
    <label for="my_setting_field"><?php _e( 'My Input', 'my-textdomain' ); ?></label>
    <input type="text" id="my_setting_field" name="my_setting_field">
    <?php
}

fonte: https://themes.artbees.net/blog/custom-setting-page-in-wordpress/