I would like to add content to the end of this page (below the form), immediately before the footer. Can I do this with a custom function, via a hook? Adding the content to the WordPress editor does not insert it at the bottom of the page as desired.

I've tried two different custom functions, but they each placed the content in an undesired location (illustration):

-- I tried using the wp_footer() hook, but that placed the content at the end of my footer.

-- I tried appending content using the_content() hook, with the code below, but that did not place the content where I wanted.

function yourprefix_add_to_content( $content ) {
  $content .= 'Your new content here';
  return $content;
add_filter( 'the_content', 'yourprefix_add_to_content' );

I can accomplish this by directly editing template, but I would rather not do that.


Unless that template that you don't want to edit has a do_action() function where you want to add the content, then no, you can't.

| improve this answer | |
  • OK thanks. And now that I think about it, that makes sense. Also, I've taken a closer look at the PHP template in-question and I now see that the post content is added before the contact form, which answers all of my questions. Let's consider this question answered then. To resolve my issue, I will end up modifying this particular theme file. It's not that big of a deal in this case, since the file in-question is already an edited version. – cag8f Jul 21 '17 at 10:17

If your template uses the default comment form you can try to add with this hook: comment_form_after, he fires after the contact form renders. Or as de other answer says, only if your theme or the plugin you're using to add this form has an action to do this.

See reference in the Codex.

| improve this answer | |
  • I don't think that's a comment form. – Jacob Peattie Jul 20 '17 at 12:49
  • 1
    Yep, probably isn't, I updated my awswer. – Cesar Henrique Damascena Jul 20 '17 at 12:52
  • That's a good point though, there's a small chance that if the form is from a plugin, that plugin might have an equivalent hook. – Jacob Peattie Jul 20 '17 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.