The "code" control

Learn how to create controls using Kirki

Back to Controls


Can't find what you're looking for? Check the github issues or edit this page to add what's missing.

Using the code control your users can enter custom CSS, JS, HTML (and others) which you can then use however you please in your themes. Internally this control uses the CodeMirror library available in WordPress.

CodeMirror is only available in WordPress 4.9+ so if used in an older WordPress installation we gracefully fallback to a textarea field.


Kirki::add_field( 'theme_config_id', [
	'type'        => 'code',
	'settings'    => 'code_setting',
	'label'       => esc_html__( 'Code Control', 'kirki' ),
	'description' => esc_html__( 'Description', 'kirki' ),
	'section'     => 'section_id',
	'default'     => '',
	'choices'     => [
		'language' => 'css',
] );


<?php echo get_theme_mod( 'code_setting', '' ); ?>
Edit this page