2015-10-16 35 views
0

我正在開發一個WordPress插件。我的插件包含一個表單。我想在標題後的某些頁面中顯示此表單,但我無法實現此目的。在標題後顯示WordPress插件

這是我如何顯示錶單直到現在。它顯示了頂部每個站點上的表單,這不是我想要的。

function pre_display_form() { 
    include("form.php"); 
} 
add_action("init", "pre_display_form"); 

我與add_actionadd_filter,但失敗的實驗。我無法找到正確的鉤子。

我知道必須有辦法做到這一點。誰能幫我 ?

+0

沒有鉤用於此。你可以嘗試js,但問題是主題可以使用任何他們想要的html標記。也許試試這個鉤子https://codex.wordpress.org/Function_Reference/get_search_form – David

回答

1

嘗試之後,它應該爲你工作: -

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"); 
     } 

}