I am editing a Custom Post Type template, and am using custom fields to enter info into a meta box to be included on the page, as well as include some static default text on all the pages.
I basically need to “chunk” together the post info in the_content along with the static text and some meta box info. Here’s what I want:
- the_content
- static text
- meta box 1
- more static text
- meta box 2
- end of the _content
I have plugins that add social buttons before the_content and a signature after the_content so I am trying to figure out how to get all my custom stuff sandwiched in between those.
If I just add the meta boxes i nthe template, they display outside of the_content and the plugins display in unwanted places.
I ended up figuring this out on my own. The solution: using functions.php and add_filter, I had to create a new function to create the default content, and it works great.
here’s the general code for anyone interested:
Note that the zero just near the end controls placement. I have a social media plugin that has a priority of “1”, and to get the default content to appear above that I have to make this a priority of “0”.
Also note the single apostrophes that open and close the code following
$content .=You basically add whatever you want between those apostrophes, and in this case I am pulling metabox info which have their own apostrophes containing code. It gets confusing!
In other words, your code should be
$content .='YOUR CUSTOM CONTENT'and within those apostrophes, add your text, code, etc. The standalone metabox code is'. get_post_meta( $post->ID, "metabox-1-slug", true ).'which is nested inside where the YOUR CUSTOM CONTENT text is.I am basically explaining this to myself, as these were the things that tripped me up so figured would explain them in detail to help someone else like me. Or me when I have to go look this up again!