Reputation: 331
I'm developing a plugin for WordPress. My plugin contains a form. I would like to display this form in certain pages after the header, but I'm unable to achieve this.
This is how I displayed the form until now. It shows the form on every site at the top, which is not what I want.
function pre_display_form() {
include("form.php");
}
add_action("init", "pre_display_form");
I was experimenting with add_action
and add_filter
, but unsuccessfully. I'm not able to find the right hook.
I know there must be a way to do it. Can anyone help me ?
Upvotes: 0
Views: 185
Reputation: 11808
Try following, it should work for you:-
add_action('wp_head','wdm_form_include');
function wdm_form_include( ) {
//here you can assign page ids where you want to display form
$page_ids = array(1,2,3);
if(in_array(get_the_ID(),$page_ids)){
//if current page id is in page ids array then including form
include("form.php");
}
}
Upvotes: 1