Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active November 21, 2022 12:31
Show Gist options
  • Save neilgee/968b6f54a94f790682c102a8ad4e343d to your computer and use it in GitHub Desktop.
Save neilgee/968b6f54a94f790682c102a8ad4e343d to your computer and use it in GitHub Desktop.
Customizer Text Block
<?php
// Change the footer text in Genesis with a back up if blank
add_filter('genesis_footer_creds_text', 'genesischild_footer_text');
function genesischild_footer_text() {
if( get_theme_mod( 'footer_text_block') != "" ) {
echo get_theme_mod( 'footer_text_block');
}
else{
echo 'Copyright &copy; 2016 · Genesis Sample Theme on Genesis Framework · WordPress · Log out'; // Add you default footer text here
}
}
// Regular WordPress theme just add in the footer template
<?php if( get_theme_mod( 'footer_text_block') != "" ): ?>
<p class="footer-text">
<?php echo get_theme_mod( 'footer_text_block'); ?>
</p>
<?php
add_action( 'customize_register', 'genesischild_register_theme_customizer' );
/*
* Register Our Customizer Stuff Here
*/
function genesischild_register_theme_customizer( $wp_customize ) {
// Create custom panel.
$wp_customize->add_panel( 'text_blocks', array(
'priority' => 500,
'theme_supports' => '',
'title' => __( 'Text Blocks', 'genesischild' ),
'description' => __( 'Set editable text for certain content.', 'genesischild' ),
) );
// Add Footer Text
// Add section.
$wp_customize->add_section( 'custom_footer_text' , array(
'title' => __('Change Footer Text','genesischild'),
'panel' => 'text_blocks',
'priority' => 10
) );
// Add setting
$wp_customize->add_setting( 'footer_text_block', array(
'default' => __( 'default text', 'genesischild' ),
'sanitize_callback' => 'sanitize_text'
) );
// Add control
$wp_customize->add_control( new WP_Customize_Control(
$wp_customize,
'custom_footer_text',
array(
'label' => __( 'Footer Text', 'genesischild' ),
'section' => 'custom_footer_text',
'settings' => 'footer_text_block',
'type' => 'text'
)
)
);
// Sanitize text
function sanitize_text( $text ) {
return sanitize_text_field( $text );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment