Setting a title on a Custom Post Type that doesn’t support titles

You could add a hidden input into the page to pre-set the title field, because it won’t be on the page(because the type doesn’t support titles).

Slug is produced from the title, so you should only need add a title value.

Something like this should work(though untested)..

add_action( 'submitpost_box', 'hidden_type_title' );

function hidden_type_title() {
    global $current_user, $post, $post_type;

    // If the current type supports the title, nothing to done, return
    if( post_type_supports( $post_type, 'title' ) )
        return;

    ?>
    <input type="hidden" name="post_title"value="<?php echo esc_attr( htmlspecialchars( get_the_author_meta( 'display_name', $current_user->data->ID ) ) ); ?>" id="title" />
    <?php
}

Though i’d perhaps suggest adding further to the code and checking if the author display name is not empty, etc… it should be enough to work with..(or get you started at least).. 🙂

Leave a Comment