I’m needing some posts to have different title colors than others, and I figured this would be most conveniently accomplished by some sort of check box on the post creation/edit screen. How would I go about adding the check box, then retrieving the value in the template?
Thanks
Yes, that’s right, you need a Custom Meta Box that’ll create the checkboxes in the Post Editing screen.
In this case, they are radio buttons, as we need only one value.
The following is the code that creates it. Put it in your theme’s
functions.php
file or create a simple plugin so this becomes theme independent.code based on this Answer
How to use it in the theme
With the proper CSS rules in place (
h1.default
,h1.red
, etc), wherever you want to apply the color class to the title (index.php
,single.php
, etc), use something like:@brasofilo work is great but if you do not want to do much coding, you can do same work from
Custom Fields
. It is hidden by default. You can make is visible fromScreen Options
. Create new field & name itcolor
and put color name invalue
field. Then put this code in you theme’sheader.php
below</head>
tag.Then search for
<h1 class="entry-title"
and put this code inside it<?php echo $id, $color;?>
. Now when evey you want to change title color, choosecolor
in custom fields drop down & write color name invalue
.