I am wondering is there some kind of hook when we open post/page editor in WordPress? I want to make a function which will grab the content from the editor and add some pieces of code in to it automatically.
You can set the default editor content or change current content using "the_editor_content" filter.
Ex: set default editor content for "Add new" post.
add_filter( 'the_editor_content', 'set_default_editor_content', 1000, 2 );
function set_default_editor_content( $content, $default_editor ) {
global $pagenow;
if ( 'post-new.php' === $pagenow ) {
ob_start();
?><p>Default content here...</p><?php
return ob_get_clean();
}
return $content;
}