I basically want to add an embedded form at the end of every blog post just below the main content area (I tried adding in the footer but it gets skipped due to showing up at the very bottom of the page). Where exactly do I put the code in the editor?
2 Answers
If you want to modify the content before it is output to the screen, use the_content filter:
add_filter( 'the_content', 'change_the_content' )
function change_the_content($content) {
$content = $content . "your additional content";
return $content;
}
See docs here: https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content .
You don't, if you want to embed something in a post, you have 2 options:
- oembed: Great for stuff like youtube, and other things, think of embeds, think of things that can be represented as URLs, e.g. copy paste a youtube URL on to a blank line and it turns into a youtube player
- shortcodes: This is how you run PHP code and insert HTML inside a post
- filters: You can append the code via
the_content
filter to your posts when they're rendered. This allows you to add things without modifying the post content
Anything that will let you copy paste a form as is into a post edit screen is going to be a security problem, dramatically increasing the chances of your site becoming hackable
-
Well, you can append a form using
the_content
filter - and that's the third option, and the best one in this case, I guess - since OP wants it to be added to every post... Commented Jun 7, 2018 at 14:17