Last active
June 1, 2023 16:10
-
-
Save cameronjonesweb/f3158f53ae7351508b561b258943b223 to your computer and use it in GitHub Desktop.
Never Fear, The Customizer Is Here! [WordCamp Sunshine Coast] demo code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'wordcampsc_link_colour', array( | |
'label' => __( 'Link Colour', 'wordcampsc' ), | |
'section' => 'colors', | |
) ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wp_customize->selective_refresh->add_partial( 'wordcampsc_link_colour', array( | |
'selector' => '#wordcampsc_customize_styles', | |
'render_callback' => function() { | |
echo 'a{color:' . get_theme_mod( 'wordcampsc_link_colour', '' ) . '};'; | |
}, | |
) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wp_customize->add_setting( 'wordcampsc_link_colour', array( | |
'type' => 'theme_mod', | |
'default' => '#337ab7', | |
'transport' => 'postMessage', | |
'sanitize_callback' => 'sanitize_hex_color', | |
) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'customize_register', 'wordcampsc_customize_register' ); | |
function wordcampsc_customize_register( WP_Customize_Manager $wp_customize ) { | |
// Settings etc go here | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wordcampsc_customize_style_output() { | |
echo 'a{color:' . get_theme_mod( 'wordcampsc_link_colour', '' ) . '};'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wp_customize->selective_refresh->add_partial( 'wordcampsc_link_colour', array( | |
'selector' => '#wordcampsc_customize_styles', | |
'render_callback' => function() { | |
echo 'a{color:' . get_theme_mod( 'wordcampsc_link_colour', '' ) . '};'; | |
}, | |
) ); | |
function wordcampsc_customize_styles() { | |
echo '<style id="wordcampsc_customize_styles">'; | |
echo 'a{color:' . get_theme_mod( 'wordcampsc_link_colour', '' ) . '};'; | |
echo '</style>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'customize_register', 'wordcampsc_customize_register' ); | |
function wordcampsc_customize_register( WP_Customize_Manager $wp_customize ) { | |
$wp_customize->add_setting( 'wordcampsc_link_colour', array( | |
'type' => 'theme_mod', | |
'capability' => 'edit_theme_options', | |
'default' => '#337ab7', | |
'transport' => 'postMessage', | |
'sanitize_callback' => 'sanitize_hex_color', | |
) ); | |
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'wordcampsc_link_colour', array( | |
'label' => __( 'Link Colour', 'wordcampsc' ), | |
'section' => 'colors', | |
) ) ); | |
if( isset( $wp_customize->selective_refresh ) ) { | |
$wp_customize->selective_refresh->add_partial( 'wordcampsc_link_colour', array( | |
'selector' => '#wordcampsc_customize_styles', | |
'render_callback' => function() { | |
wordcampsc_customize_style_output(); | |
}, | |
) ); | |
} else { | |
wp_enqueue_script( 'wordcampsc_customizer', get_template_directory_uri() . '/customizer.js', array( 'customize-preview' ), NULL, true ); | |
} | |
} | |
add_action( 'wp_head', 'wordcampsc_customize_styles' ); | |
function wordcampsc_customize_styles() { | |
echo '<style id="wordcampsc_customize_styles">'; | |
wordcampsc_customize_style_output(); | |
echo '</style>'; | |
} | |
function wordcampsc_customize_style_output() { | |
echo 'a{color:' . get_theme_mod( 'wordcampsc_link_colour', '' ) . '};'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( isset( $wp_customize->selective_refresh ) ) { | |
$wp_customize->selective_refresh->add_partial( 'wordcampsc_link_colour', array( | |
'selector' => '#wordcampsc_customize_styles', | |
'render_callback' => function() { | |
echo 'a{color:' . get_theme_mod( 'wordcampsc_link_colour', '' ) . '};'; | |
}, | |
) ); | |
} else { | |
wp_enqueue_script( 'wordcampsc_customizer', get_template_directory_uri() . '/customizer.js', array(), NULL, true ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp_head', 'wordcampsc_customize_styles' ); | |
function wordcampsc_customize_styles() { | |
echo '<style id="wordcampsc_customize_styles">'; | |
echo 'a{color:' . get_theme_mod( 'wordcampsc_link_colour', '' ) . '};'; | |
echo '</style>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment