2015-11-17 70 views
0

當有人進入「創建帖子頁面」(不更新帖子頁面)並預先填寫標題和正文字段時,是否有一種方法可以掛鉤?Hook pre create Post

喜歡的東西:

add_filter('WP_FILTER_ENTERS_CREATE_POST_PAGE', 'my_function_callback') 

function my_function_callback() { 

    # dummy title 
    $title  = 'My Post Tile'; 

    # dummy post content 
    $post_body = '<p>Hi it is post body</p>'; 

    # set editor content 
    wp_editor($postBody, 'my_editor_id'); // not sure 

    # set post title 
    ??????? 

} 

感謝提前:)

+0

可能重複的[爲Wordpress自定義帖子類型設置默認標題?](http://stackoverflow.com/questions/20254827/set-default-title-for-wordpress-custom-post-types) – rnevius

+0

我想填寫字段(標題和內容)當wp-admin/post-new.php加載不在用戶點擊提交按鈕後發佈.. –

回答

2

法典https://codex.wordpress.org/Plugin_API/Filter_Reference搜索,我發現 「default_content」 和 「default_title」 過濾器,正是我尋找後!

# filter content 
add_filter('default_content', 'default_editor_content', 10, 2); 

# filter content function callback 
function default_editor_content($content, $post){ 
    $content = "<p><strong>Heloo!!</strong> I am custom content</p>"; 

    return $content; 
} 

# filter title 
add_filter('default_title', 'default_title_value', 10, 2); 

# filter title function callback 
function default_title_value($title, $post){ 
    $title = "Custom post Title here"; 

    return $title; 
} 

此後......當打開wp-admin/post-new.php時,標題輸入欄和編輯器內容顯示充滿了默認值。