将以下代码用于functions.php
文件
function change_title_yt( $post_id ) {
$current_title = $_POST[\'post_title\'];
$doc = new DOMDocument();
$doc->preserveWhiteSpace = FALSE;
$doc->loadHTMLFile($current_title);
$title_div = $doc->getElementById(\'eow-title\');
$title = $title_div->nodeValue;
$my_args = array(
\'ID\' => $post_id,
\'post_title\' => $title
);
if ( ! wp_is_post_revision( $post_id ) ){
// unhook this function so it doesn\'t loop infinitely
remove_action(\'save_post\', \'change_title_yt\');
// update the post, which calls save_post again
wp_update_post( $my_args );
// re-hook this function
add_action(\'save_post\', \'change_title_yt\');
}
}
add_action(\'save_post\', \'change_title_yt\');