Adding a second title to a Custom Post in WordPress?

php, wordpress

Solution

Update: there's an easy way to do it using some hooks and managing the `save_post` just like a regular meta box.

No, there can only be one title.

You have to create a Custom Field to record the value of a Second Title.

And, problem is that it cannot be put between the title and the content box.

I suggest the plugin Advanced Custom Fields. It's been actively developed and is quite handy for generating a variety of CF's.

This is how I'd do it, click on the images to enlarge:

Configure one Advanced Custom Field

Result in Custom Post Type screen

Moving the field with jQuery help

add_action( 'admin_head', 'so_13726274_move_field' );

function so_13726274_move_field()
{
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($)
        {     
            $('#acf-text').prependTo('#postdivrich');
            $('#acf-field_50baa73272855').css('width','100%');
        });
    </script>
    <?php
}

Results in

jQuery Notes

- `$('#acf-text')` is the container div, corresponds to "#acf-FIELD_NAME"

- `$('#acf-field_50baa73272855')` is the text field itself, we need this command because the width gets shorter when we move the container div

- the text field #ID has to be detected in your own installation as it won't be the same, use Chrome Inspector or FireBug

Problem

At the moment I am just learning about Custom Post Types so I am unsure how to proceed from here. I created a custom post for events, it is almost identical to a normal post with just slightly different wording. But the reason I made one is because I want to add a second title after the initial title. To make this as easy as possible for the user I would ideally like this text field just underneath the first one above the main editor. Just wondering how do I add that here? ``` register_post_type('events', array( 'label' => 'Events', 'description' => 'Events section', 'public' => true,'show_ui' => true, 'show_in_menu' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => ''), 'query_var' => true, 'exclude_from_search' => false, 'supports' => array('title','editor','thumbnail','author','page-attributes',), 'taxonomies' => array('category',), 'labels' => array ( 'name' => 'Events', 'singular_name' => 'Event', 'menu_name' => 'Events', 'add_new' => 'Add Event', 'add_new_item' => 'Add New Event', 'edit' => 'Edit', 'edit_item' => 'Edit Event', 'new_item' => 'New Event', 'view' => 'View Event', 'view_item' => 'View Event', 'search_items' => 'Search Events', 'not_found' => 'No Events Found', 'not_found_in_trash' => 'No Events Found in Trash', 'parent' => 'Parent Event', ), ) ); ``` `'title'` seems to be the standard one, so I'm wondering if I can create another instance of that?

Original source