Categories
Genesis Tutorials

Adding A Title To A Custom Post Type Archive Page

Generally, custom post type archive pages like portfolio archives, don’t include a title. The reason for this is there’s no page template created when the custom post type is generated from the functions.php file. So you can’t simply add a title like you can with a page, post or standard archive page like which categories, tags and author archives use.

Rather than bore you with the reasons, i’ll simply give you the code which works.

Update: You can now add a archive settings page to any CPT using Genesis 2.0. Simply add these

'has_archive' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ),

Here’s an example of what the full code snippet should look like:

/** Create portfolio custom post type */
add_action( 'init', 'portfolio_post_type' );
function portfolio_post_type() {
	register_post_type( 'portfolio',
		array(
			'labels' => array(
				'name' => __( 'Portfolio', 'child theme text' ),
				'singular_name' => __( 'Portfolio', 'child theme text' ),
			),
			'exclude_from_search' => true,
			'has_archive' => true,
			'hierarchical' => true,
			'menu_icon' => get_stylesheet_directory_uri() . '/images/icons/portfolio.png',
			'public' => true,
			'show_ui' => true,
			'show_in_menu' => true,
			'rewrite' => array( 'slug' => 'portfolio' ),
			'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ),
		)
	);
}
Note: This relies on custom permalinks set up in WordPress under Settings > Permalinks. You may have to resave them after setup of CPTs or changing the code.

This code will come in handy when using Genesis child themes like the Executive theme by StudioPress which uses a custom post type for the portfolio.

This code will display your custom post type archive title for your custom post type in the same way your category archive titles are displayed in the genesis_before_content hook position using the h1 heading size.

This code will also display your custom post type archive title but in the genesis_after_header hook position and aligns the title to the centre with a h2 heading size.

This code does the same as the code above however can be used for multiple custom post type archive titles. Not sure why you’d want to use the same titles on different custom post type archive pages but you may do for some reason.

The conditional tag used is:

is_post_type_archive

You can use different hooks with this code however you’ll find the genesis_post_title hook will also include the archive page title on posts attached to that custom post type archive which won’t be ideal.

This is the reason i have included the genesis_after_header and the genesis_before_content hooks as they only display the custom post type archive page title on the archive page and not on all the posts titles included in that archive.

Related Tutorials

Categories
WordPress Tips

3 Ways To Change & Convert Different Post Types In WordPress

Change Post TypeRecently i changed themes on a client site where their property listing for sales and rentals where published as posts.

The problem was that the new theme was using a custom post type named property.

In order to be able to use all the functions that the new theme offers for the properties post type i had to change over 50 posts from the post type to property.

There’s different ways to do this:

  1. Using the  Post Type Switcher plugin and changing them one by one
  2. Exporting a backup of the posts (Tools > Export) and changing the post type using Notepads search and replace feature
  3. Bulk converting post types using the Convert Post Types plugin

I actually used the post type switcher plugin because i needed to manually edit every page anyway.

If i didn’t need to edit every page, i would have used the Convert Post Types plugin because it would save a lot of time however i did test all 3 solutions so here they are in more detail.

Post Type Switcher

This plugin simply adds a function under the Publish immediately feature in the top right haqnd corner of the Edit Post screen.

You can then change post types manually on each post or custom post type.

You can’t bulk change post types unlike the Convert Post Types plugin.

Post Types

Changing Post Type Using Notepad ++

You can use the WordPress export tool to export different post types and then use the search and replace function Notepad ++ provides to change all post types.

No need to use this feature if you install the Convert Post Types plugin.

Notepad Search and Replace

Convert Post Types Plugin

This plugin is the most flexible solution for changing post types.

The reason for this is that you can change anything to anything in bulk or change different categories and post types individually in bulk.

Convert Post Types

If you are thinking about changing themes and concerned about what will happen to different post types on either themes you don’t need to worry as these solutions cover all bases.

Anything here i haven’t covered or anything you would like to know more about then simply leave a comment which i will reply to within one day.

Change Custom Post Types Using SQL Query in phpMyAdmin

You might also like to use phpMyAdmin to run an sql query to change the name of all existing ( Already published ) single CPT’s:

Use SQL Query In phpMyAdmin To Change Custom Post Types

Related Tutorials