Custom Post Type UI
[resolved] Where to Add the code in functions.php (6 posts)

  1. snaushads
    Posted 5 years ago #

    Everything is working fine.

    I just want to know where should i add the Custom Post Type Code in functions.php

    As in before this function Or that function.
    1. Theme: TwentyEleven
    2. Should the placement change with Theme ?

    I am a newbie with PHP.

  2. popper
    Posted 5 years ago #

    Hi snaushads. Generally, it won't matter where you add the code,as long as you add it insede the <?php ?> tags. Just paste it in the end of the file and it should work fine.

  3. snaushads
    Posted 5 years ago #

    @popper Thanks for the update.

    I did it, and could get the new Post type in Admin.

    But when i tested by adding content in the post type.

    I get below result

    Not Found

    Apologies, but the page you requested could not be found. Perhaps searching will help.

    Something isn't working as it should.

    Note: I got this snippet from http://themergency.com/generators/wordpress-custom-post-types/

  4. popper
    Posted 5 years ago #

    That's strange. I tested the tool you used to generate the code, and it works fine for me. Can you paste the code you used on pastebin.com so we can take a look at it?

  5. snaushads
    Posted 5 years ago #

    add_action( 'init', 'register_cpt_product' );
        function register_cpt_product() {
        $labels = array(
        'name' => _x( 'Products', 'product' ),
        'singular_name' => _x( 'Product', 'product' ),
        'add_new' => _x( 'Add New', 'product' ),
        'add_new_item' => _x( 'Add New Product', 'product' ),
        'edit_item' => _x( 'Edit Product', 'product' ),
        'new_item' => _x( 'New Product', 'product' ),
        'view_item' => _x( 'View Product', 'product' ),
        'search_items' => _x( 'Search Products', 'product' ),
        'not_found' => _x( 'No products found', 'product' ),
        'not_found_in_trash' => _x( 'No products found in Trash', 'product' ),
        'parent_item_colon' => _x( 'Parent Product:', 'product' ),
        'menu_name' => _x( 'Products', 'product' ),
        $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'description' => 'Custom Post Type for Products',
        'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'revisions', 'post-formats' ),
        'taxonomies' => array( 'category', 'post_tag' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        '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' => 'post'
        register_post_type( 'product', $args );

    This is the exact code generated, thanks for checking.

    As of now, i have installed Custom Post Type UI and giving it a try

  6. popper
    Posted 5 years ago #

    Works fine for me both in my theme and twenty eleven. If you have any plugins or custom permalinks, try deactivating them, see if that helps.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Post Type UI
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic