Sometimes you want to move the traditional editor for the post to another location, probably inside a meta box. It will keep everything more organized. For example, if you have an event post type, then you might have the following data:
- Start date and time
- End date and time
Then keeping the description (which can be the post content) along with other fields make users easier to fill in the data. While this is impossible to do that with the default WordPress editor, we can do that with the Meta Box plugin.
The steps to do that are describe below:
- Remove the default editor (we don’t want to display it at the top)
- Create a new wysiwyg field
- Set that field take the post content as the default value
- Save that field content into post content
The code is quite straight forward as below:
There are 2 things important in the code above:
- To make Meta Box save the wysiwyg content to post content, we have to set it
'id' => 'content'. This
idis used to tell WordPress to get the submitted value and save it to post content.
- Because we use the WordPress’s id for the field, some WordPress style is applied and makes the field look weird. We have to use a
custom_htmlfield to output some CSS to fix it. Note that you might want to enqueue another stylesheet to do the same job. Here we use the
custom_htmlfor the quick fix, it just works.
The code above works for
post. If you want to make it work for another post type, don’t forget to change the post type in the code above!