Support » Developing with WordPress » Auto-Generate Post Title

  • I am trying to find a way to auto-generate a post title when using the ‘status’ post format. I would like the title to auto-generate to “Status Update – <time> – <date>”. Any advice on if this is possible and how to make it happen would be appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Add a function in the functions.php file witin your Child Theme –

    function set_custom_title( $value, $post_id ) {
    $label = 'Status Update';
    $date = date("Ymd");
    $date =  date("Y-m-d", strtotime($date));
    $timeis = date("h:i:sa");
    $title = $label . ' - ' . $timeis . ' - ' . $date;
    $post_slug = sanitize_title_with_dashes ($title,'','save');
    $post_slugsan = sanitize_title($post_slug);
    $value['post_title'] = $title;
    $value['post_name'] = $post_slugsan;
    return $value;
    add_filter( 'wp_insert_post_data' , 'set_custom_title' , '10', 2 );

    This will generate the new Post Title on Save.

    Thread Starter Jim Lunsford


    Thank you for your reply.

    Is there a way to only auto-generate a title when the post format that is selected is status?

    Also when I tested it the time was off by five hours from my time zone and the date displayed as 1970-01-01.

    > the post format that is selected is status?

    I don’t know what this means.
    You man you have a *custom post type* that is named ‘status’ ?

    You can just add a conditional loop, you may be able to use is_singular :

    or you may have to get the post types first, then check against it :

    Do you have your WP settings set properly :
    Or, you can check with your host.

    Thread Starter Jim Lunsford


    This is what I mean by post format:

    I’m fairly certain that my time is configured properly. Is it possible that the server is not?

    Can you ftp or ssh over to the server and check the timestamp on your files ?

    The date is likely returning the unix epoch.

    Change to date variable from this :
    $date = date(“Y-m-d”, strtotime($date));
    to this :
    $date = date(“Y-m-d”);

    For time, use your locale – i.e.
    $timeis = date(“h:i:sa”);

    Moderator bcworkz


    The $post_id parameter collected in corrinarusso’s code isn’t really the post ID, it’s an array of slashed but otherwise unmodified post data (see here). I believe the post format selected is in there somewhere, probably under “tax_input” since post formats are actually taxonomy terms. If it’s in there, you can conditionally only set titles this way when the “status” format term is assigned.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Auto-Generate Post Title’ is closed to new replies.