What I'm setting up, I thought would be quite simple. In fact, I'm sort of amazed that the answer didn't just pop up after a half hour of searching here.

Here is the code to create my CPT:

register_post_type('headline', array(
'labels'                => array(
    'name'                  => 'Headlines',
    'singular_name'         => 'Headline',
    'add_new'               => 'Add Headline',
    'add_new_item'          => 'Add Headline',
    'edit_item'             => 'Edit Headline',
    'new_item'              => 'New Headline',
    'all_items'             => 'All Headlines',
    'view_item'             => 'View Headline',
    'search_items'          => 'Search Headlines',
    'not_found'             =>  'No matching headlines found',
    'not_found_in_trash'    => 'No matching headlines found in Trash', 
    'parent_item_colon'     => '',
    'menu_name'             => 'Headlines'
'description'           => 'Headlines from around the world.',
'public'                => true,
'supports'              => array('title', 'editor', 'author', 'excerpt', 'thumbnail', 'trackbacks', 'comments', 'revisions'),
'taxonomies'            => array('category', 'post_tag'),
'register_meta_box_cb'  => 'DfePostTypesHeadline::add_meta_boxes',
'has_archive'           => true,
'rewrite'               => array(
    'with_front'    => false
'can_export'            => true

The problem is the "with_front" call. Or rather, with the rewrite rules themselves. I've got my flush_rewrite_rules() call happening on plugin activation/deactivation. And I can see that the .htaccess file is getting rewritten, so it's working. But WordPress still cannot recognize my new permalink structure.

I'm not sure if this is relevant or not, but my register_post_type call is happening on the "init" hook. I'm wondering if a different hook is necessary?

/* Giddyup */
public function DFEPostTypes() {
    add_action( 'init', 'DFEPostTypes::register_content_types' );
    add_action( 'admin_menu', 'DFEPostTypes::admin_pages' );
    add_action( 'admin_enqueue_scripts', 'DFEPostTypes::admin_scripts' );
    add_filter( 'template_include', 'DFEPostTypes::template' );
    // Flush rewrite rules:
    register_activation_hook( __FILE__, 'DFEPostTypes::flush_rewrite' );
    register_deactivation_hook( __FILE__, 'DFEPostTypes::flush_rewrite' );

register_content_types() is the function that handles dynamically calling and registering the content types I work with.

1 Answer 1


You have to register your post type before you flush the rules. Your init action doesn't run on plugin activation, so your flush_rewrite method should call register_content_types first before flushing the rules.

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.