Last active
August 29, 2015 14:08
-
-
Save westonruter/2180ab8624a210e6eefb to your computer and use it in GitHub Desktop.
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
<?php | |
// This is demo code only, to show how to use certain types of functionality. | |
add_action('after_setup_theme','themedemo_setup'); | |
function themedemo_setup() { | |
add_theme_support( 'custom-background', array( | |
'default-color' => 'f79797', | |
) ); | |
} | |
add_action ('admin_menu', 'themedemo_admin'); | |
function themedemo_admin() { | |
// add the Customize link to the admin menu | |
add_theme_page( 'Customize', 'Customize', 'edit_theme_options', 'customize.php' ); | |
// Note: "customize.php" works with the currently active theme only. | |
// Adding ?theme=themedemo to it would allow links to customize non-active themes, but | |
// this makes no sense in the theme functions.php file of a theme.. could work in a plugin though... | |
} | |
// add some settings and such | |
add_action('customize_register', 'themedemo_customize'); | |
function themedemo_customize($wp_customize) { | |
$wp_customize->add_section( 'themedemo_demo_settings', array( | |
'title' => 'Demonstration Stuff', | |
'priority' => 35, | |
) ); | |
$wp_customize->add_setting( 'some_setting', array( | |
'default' => 'default_value', | |
) ); | |
$wp_customize->add_control( 'some_setting', array( | |
'label' => 'Text Setting', | |
'section' => 'themedemo_demo_settings', | |
'type' => 'text', | |
'active_callback' => function () { | |
return isset( $_GET['enable_control'] ); | |
} | |
) ); | |
$wp_customize->add_setting( 'some_other_setting', array( | |
'default' => '#000000', | |
) ); | |
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'some_other_setting', array( | |
'label' => 'Color Setting', | |
'section' => 'themedemo_demo_settings', | |
'settings' => 'some_other_setting', | |
'active_callback' => '__return_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
<html> | |
<head> | |
<link rel="stylesheet" href="<?php echo get_stylesheet_uri() ?>" /> | |
<?php wp_head(); ?> | |
</head> | |
<body <?php body_class(); ?>> | |
<h1><?php bloginfo('name'); ?></h1> | |
<h2><?php bloginfo('description'); ?></h2> |
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
<?php get_header(); ?> | |
<h3>Theme Customizer Demo, using theme_mod and <em>no</em> settings page!</h3> | |
<?php if ( isset( $_REQUEST['enable_control'] ) ): ?> | |
<p><a href="<?php echo home_url( '/' ) ?>">Disable <code>some_setting></code> Control</a></p> | |
<?php else: ?> | |
<p><a href="<?php echo home_url( '/?enable_control=1' ) ?>">Enable <code>some_setting</code> Control</a></p> | |
<?php endif; ?> | |
<pre> | |
<?php | |
echo 'some_setting => ' .get_theme_mod( 'some_setting', 'default_value' )."\n"; | |
echo 'some_other_setting => ' .get_theme_mod( 'some_other_setting', '#000000' )."\n"; | |
echo 'non_existent_setting => '.get_theme_mod( 'non_existent_setting', 'default_value' )."\n"; | |
?> | |
</pre> | |
<?php get_footer(); ?> |
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
/* | |
Theme Name: Theme Customizer Demo | |
Theme URI: http://ottopress.com/2012/theme-customizer-part-deux-getting-rid-of-options-pages | |
Author: Otto | |
Author URI: http://ottopress.com/ | |
Description: This isn't a real theme, it's a demonstration of using theme options without an options page. | |
Version: 1.0 | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment