GithubHelp home page GithubHelp logo

customizer-library-demo's Introduction

Customizer Library Demo

An example theme that shows how to work with the Customizer Library.

About

Read the description for the Customizer Library project.

Installation

To install this demo and the required submodule, use: git clone --recursive [email protected]:devinsays/customizer-library-demo

The Customizer Library is included in this theme as a git submodule. To include it in your own projects the same way, navigate to the directory and use:

git submodule add [email protected]:devinsays/customizer-library customizer-library

Define Options

This theme demo includes the following customizer options as examples:

  • Logo
  • Primary Color
  • Secondary Color
  • Border Color
  • Primary Font (Google Fonts)
  • Secondary Font (Google Fonts)
  • Example Checkbox
  • Example Select
  • Example Radio
  • Example Textarea

The options are defined as an array in "inc/customizer-options.php".

Here's an example of how to set up a customizer section for "Logo" and a customizer control the an image uploader:

// Logo
$section = 'logo';

$sections[] = array(
	'id' => $section,
	'title' => __( 'Logo Example', 'demo' ),
	'priority' => '30'
);

$options['logo'] = array(
	'id' => 'logo',
	'label'   => __( 'Logo', 'demo' ),
	'section' => $section,
	'type'    => 'upload',
	'default' => '',
);

After all the options and sections are defined, load them with the Customizer Library:

// Adds the sections to the $options array
$options['sections'] = $sections;

$customizer_library = Customizer_Library::Instance();
$customizer_library->add_options( $options );

Styles

The Customizer Library has a helper class to output inline styles. This code was originally developed by The Theme Foundry for use in Make. To see how it works, see "inc/styles.php".

CSS selector(s) and value are passed to Customizer_Library_Styles class like this:

Customizer_Library_Styles()->add( array(
	'selectors' => array(
		'.primary'
	),
	'declarations' => array(
		'color' => $color
	)
) );

Fonts

The Customizer Library has a helper functions to output font stacks and load inline fonts. This code was also developed by The Theme Foundry for use in Make. You can see an example of font enqueing in "inc/mods.php":

function demo_fonts() {

	// Font options
	$fonts = array(
		get_theme_mod( 'primary-font', customizer_library_get_default( 'primary-font' ) ),
		get_theme_mod( 'secondary-font', customizer_library_get_default( 'secondary-font' ) )
	);

	$font_uri = customizer_library_get_google_font_uri( $fonts );

	// Load Google Fonts
	wp_enqueue_style( 'demo_fonts', $font_uri, array(), null, 'screen' );

}
add_action( 'wp_enqueue_scripts', 'demo_fonts' );

Fonts can be used in inline styles like this:

// Primary Font
$setting = 'primary-font';
$mod = get_theme_mod( $setting, customizer_library_get_default( $setting ) );
$stack = customizer_library_get_font_stack( $mod );

if ( $mod != customizer_library_get_default( $setting ) ) {

	Customizer_Library_Styles()->add( array(
		'selectors' => array(
			'.primary'
		),
		'declarations' => array(
			'font-family' => $stack
		)
	) );

}

customizer-library-demo's People

Contributors

devinsays avatar mauryaratan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.