简体   繁体   中英

Automatically appending post title into post content upon publishing of post?

Please tell me, how can I fetch the post title and append it into the content of that post when I click the publish button?

Thank you!

The wp_insert_post_data filter allows you to manipulate the post data before it is inserted in the database:

function so16876611_insert_post_data( $data , $postarr )
{
    $data['post_content'] = $data['post_content'] . $data['post_title'];
    return $data;
}
add_filter( 'wp_insert_post_data', 'so16876611_insert_post_data', 99, 2 );

You would need to access save_post hook that's being triggered after creating/updating page. It would look something like below:

function custom_save_post($post_id) 
{
    $_POST['content']=  $_POST['post_name'].$_POST['content']; 
}
add_action("save_post", "custom_save_post");

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM