If my post title is https://www.youtube.com/watch?v=PJmMiZH3Q6I I want it to be converted to original video title which is "Ras Cricket - Fyah"

Is there a way without API stuff cause it seems hard.

1 Answer 1


Use the following code into your functions.php file.

function change_title_yt( $post_id ) {
    $current_title = $_POST['post_title'];

    $doc = new DOMDocument();
    $doc->preserveWhiteSpace = FALSE;

    $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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.