Skip to content

Instantly share code, notes, and snippets.

@devinsays
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinsays/f0ed4a4d52b5f5a72e7b to your computer and use it in GitHub Desktop.
Save devinsays/f0ed4a4d52b5f5a72e7b to your computer and use it in GitHub Desktop.
Customize control to output arbitrary content or HTML.
$wp_customize->add_setting( 'example-control', array() );
$wp_customize->add_control( new Prefix_Custom_Content( $wp_customize, 'example-control', array(
'section' => 'title_tagline',
'priority' => 20,
'label' => __( 'Example Control', 'govpress' ),
'content' => __( 'Content to output. Use <a href="#">HTML</a> if you like.', 'textdomain' ) . '</p>',
'description' => __( 'Optional: Example Description.', 'textdomain' ),
) ) );
if ( class_exists( 'WP_Customize_Control' ) && ! class_exists( 'Prefix_Custom_Content' ) ) :
class Prefix_Custom_Content extends WP_Customize_Control {
// Whitelist content parameter
public $content = '';
/**
* Render the control's content.
*
* Allows the content to be overriden without having to rewrite the wrapper.
*
* @since 1.0.0
* @return void
*/
public function render_content() {
if ( isset( $this->label ) ) {
echo '<span class="customize-control-title">' . $this->label . '</span>';
}
if ( isset( $this->content ) ) {
echo $this->content;
}
if ( isset( $this->description ) ) {
echo '<span class="description customize-control-description">' . $this->description . '</span>';
}
}
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment