Skip to content
Custom fields for WordPress that are quick to build and quick to load. Get Pro

Sections and media

A color field as a CSS variable

A color picked in the admin becomes a CSS variable on the page.

1 minute Works with the free plugin

PHP
<?php
$accent = ugly_get( 'accent' );

if ( preg_match( '/^#[0-9a-fA-F]{6}$/', (string) $accent ) ) {
	echo '<style>:root { --accent: ' . esc_html( $accent ) . '; }</style>';
}

Check it before you put it in a <style> tag. The field cleans it when saving, but a style tag is a place to be careful.