I would like to add a drop down menu for color branding on post and pages.
Menu will hold a list off 4 brand colors (black, red, blue, green)
The selected color will change css on H tags, Blockquotes, links, etc. in the post content area.
Pretty easy to make the menu.
What would the PHP look like? This variable, call these classes?
Where would the PHP go?
You are talking about filtering the content. This would not be easy to add. You’d need to create a new filter for “the_content”, then you’d need to parse all the HTML, find the parts that you want to change and alter them.
The other choice is to add custom CSS using the “get_header” hook
add_action('get_header', 'my_custom_page_css');
function my_custom_page_css() {
// we need to get the post ID because this is outside the loop
$queried_object = get_queried_object();
if (!isset($queried_object->ID)) {
// not a post
return;
}
$post_id = $queried_object->ID;
?>
<style type="text/css">
h1 {
color: <?php the_field('heading_color', $post_id);
}
</style>
<?php
}
I know this is an old topic so hopefully this helps someone.