0
votes

Instead of putting my custom post type in to my theme, I decided I'd create a plugin (as my theme is likely to change in the future).

I created a folder for my plugin and made a file (myplugin.php) with content like:

<?php
   /*
   Plugin Name: myplugin
   Plugin URI: http://www.mywebsite.com
   Description: Custom post types for my website
   Version: 1.0
   Author: my name
   Author URI: http://www.mywebsite.com
   License: Private
   */
?>

And added my custom post type to a functions.php file, like so:

<?php
add_action( 'init', 'register_cpt_portfolio' );

function register_cpt_portfolio() {

    $labels = array( 
        'name' => _x( 'Portfolio', 'portfolio' ),
        'singular_name' => _x( 'Portfolio', 'portfolio' ),
        'add_new' => _x( 'Add New', 'portfolio' ),
        'add_new_item' => _x( 'Add New Portfolio', 'portfolio' ),
        'edit_item' => _x( 'Edit Portfolio', 'portfolio' ),
        'new_item' => _x( 'New Portfolio', 'portfolio' ),
        'view_item' => _x( 'View Portfolio', 'portfolio' ),
        'search_items' => _x( 'Search Portfolio', 'portfolio' ),
        'not_found' => _x( 'No portfolio found', 'portfolio' ),
        'not_found_in_trash' => _x( 'No portfolio found in Trash', 'portfolio' ),
        'parent_item_colon' => _x( 'Parent Portfolio:', 'portfolio' ),
        'menu_name' => _x( 'Portfolio', 'portfolio' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => true,
        'description' => 'To display completed works.',
        'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields' ),
        'taxonomies' => array( 'category' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,


        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'page'
    );

    register_post_type( 'portfolio', $args );
}
?>

However, after activating the plugin, I don't see my custom post type - have I missed any steps here? Thanks for any help!

1

1 Answers

0
votes

Instead of using a functions.php file I just put the CPT in to the main plugin php file and it seems to work well. I'll accept this as the answer in two days when it will let me unless anyone has a better suggestion on how I should do this :).