下面的代码可以工作,请阅读内联注释。将其粘贴到主题函数中。php或插件。
唯一的问题是,只有在选择模板、保存/更新帖子并且编辑器为空时,它才会起作用。
<?php
function wpse_177576_update_editor_content( $post_id ) {
if ( wp_is_post_revision( $post_id ) )
return;
$post = get_post( $post_id );
$content = apply_filters( \'the_content\', $post->post_content );
if ( \'\' != $content )
return; // content already exists, we don\'t want to overwrite it.
$template = get_post_meta( $post_id, \'_wp_page_template\', true ); // Returns the template file name i.e. page-accordion.php
if ( $template == \'page-accordion.php\' ) { // change "page-accordion.php" to the filename of your template
$content = \'<h1>modify this header for title</h1>
<div id="accordion">
write you content here
</div>\';
}
/**
* Update the post with template content
*/
wp_update_post( array(
\'ID\' => $post_id,
\'post_content\' => $content
) );
}
add_action( \'save_post\', \'wpse_177576_update_editor_content\' );