Support » Plugins and Hacks » Custom Post Type UI » Where to Add the code in functions.php

  • Resolved snaushads

    (@snaushads)


    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 ?

    Note:
    I am a newbie with PHP.

Viewing 5 replies - 1 through 5 (of 5 total)
  • popper

    (@julialasarte)


    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.

    @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/

    popper

    (@julialasarte)


    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?

    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

    popper

    (@julialasarte)


    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Where to Add the code in functions.php’ is closed to new replies.