Custom Snippet

Use this tool to share WordPress snippets with the community.

  Save Snippet
function gwp_pc_action_wp_head() {
	// if we're not on a "Post"
	if ( ! is_singular( 'post' ) )
		return;

	// include file with color sanitization functions
	include ABSPATH . 'wpfunction gwp_pc_action_wp_head() {
	// if we're not on a "Post"
	if ( ! is_singular( 'post' ) )
		return;

	// include file with color sanitization functions
	if ( ! function_exists( 'sanitize_hex_color' ) ) {
	    include_once ABSPATH . 'wp-includes/class-wp-customize-manager.php';
	}

	// fetch and sanitize the colors
	$primary_color   = sanitize_hex_color( get_post_meta( get_the_id(), 'gwp_pc_primary_color',   true ) );
	$secondary_color = sanitize_hex_color( get_post_meta( get_the_id(), 'gwp_pc_secondary_color', true ) );

	// check if either is empty, then do not display at all
	if ( empty( $primary_color ) || empty( $secondary_color ) )
		return;

	?>
	<!-- GWP Color Styles -->
	<style>
	.entry-header .entry-title {
		color: <?php echo $primary_color; ?>;
		background-color: <?php echo $secondary_color; ?>;
	}
	</style>
	<?php
}
add_action( 'wp_head', 'gwp_pc_action_wp_head' );-includes/class-wp-customize-manager.php';

	// fetch and sanitize the colors
	$primary_color   = sanitize_hex_color( get_post_meta( get_the_id(), 'gwp_pc_primary_color',   true ) );
	$secondary_color = sanitize_hex_color( get_post_meta( get_the_id(), 'gwp_pc_secondary_color', true ) );

	// check if either is empty, then do not display at all
	if ( empty( $primary_color ) || empty( $secondary_color ) )
		return;

	?>
	<!-- GWP Color Styles -->
	<style>
	.entry-header .entry-title {
		color: <?php echo $primary_color; ?>;
		background-color: <?php echo $secondary_color; ?>;
	}
	</style>
	<?php
}
add_action( 'wp_head', 'gwp_pc_action_wp_head' );