Hook pre create Post

时间:2015-11-17 00:09:32

标签: wordpress

当某人进入"创建帖子页面时,是否有一种方法可以勾选" (不更新帖子页面)并预填标题和正文字段?

类似的东西:

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
    ???????

}

提前致谢!)

1 个答案:

答案 0 :(得分:3)

在Codex 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时,标题输入字段和编辑器内容显示为填充默认值。