Assign a Class to the Input Text Field of a Custom Metabox
-
On the past site that I’ve worked on I used the Text tab in the Edit Page screen to insert HTML elements, and to add classes and ids to these elements so that I could attach specific CSS styles in the theme’s style.css file. For example, I would put the following into the Text tab of the Edit Page screen:
<p class=”myCustomParagraph”>Here is my sentence.</p>
… and then add this to the style.css file of my theme:
.myCustomParagraph {font-size:10px;}
The problem with this is that the client would often go to this Text tab to edit the sentence, and accidentally delete some of the HTML.
I’d like to have future clients be able to go to the Edit Page screen, and be presented with a custom metabox that would allow them to type the words “Here is my sentence” into the metabox’s text field. This way they could type in whatever words they wanted without having to see (or accidentally delete) any of the <p> elements, or class names. But, behind the scenes, whatever they typed in would automatically be assigned to the myCustomParagraph class, and be given a font size of 10px.
I’ve already set up the custom metabox itself, along with the input field, but I don’t know how to assign a class to the content that would be typed into the input field, so that when I viewed that Page in the browser I’d see the words showing up as 10px in size.
Your help would be greatly appreciated.
- The topic ‘Assign a Class to the Input Text Field of a Custom Metabox’ is closed to new replies.