Trying to add a settings field but it’s not working

[ad_1]

I’m trying to add a single tick-box option to General settings using the following code. However, it doesn’t save the result (which should be in the option named world_domination_toggle.

/**
 * Add to settings
 *
 * Add a field to the general settings screen for switching the image on/off
 */
function world_domination_settings_init() {

	add_settings_field( 'world_domination_toggle', __( 'Disable World Domination image', 'world-domination' ), 'world_domination_image_option', 'general', 'default', array( 'label_for' => 'world_domination_toggle' ) );

	register_setting( 'general', 'world_domination_toggle' );

}

add_action( 'admin_init', 'world_domination_settings_init' );

/**
 * Show image option switch
 *
 * Output the settings field for toggling the image on the dashboard
 */
function world_domination_image_option() {

	echo '<label><input name="world_domination_toggle" id="world_domination_toggle" type="checkbox" value="1" ' . checked( 1, get_option( 'world_domination_toggle', 1 ), false ) . '/></label>';

}

For a while it worked and then as soon as I changed some code it stopped – I reverted the code but it’s refused to work since and it’s driving me mad!

Does anybody have a clue as to what’s going wrong here?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer