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 ?
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");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.