WordPress   

Add new custom post without plugin in WordPress

Below given code snippet is customized for creating PDF files post. You can easily change the values in this code snippet to customize it according to your requirements. After customizing this code snippet, just paste it in the functions.php file of active theme and you are done.

 function create_custom_post_pdf() {
  $labels = array(
    'name'               => esc_html__( 'PDF Files', 'text-domain' ),
    'singular_name'      => esc_html__( 'PDF File', 'text-domain' ),
    'add_new'            => esc_html__( 'Add New', 'text-domain' ),
    'add_new_item'       => esc_html__( 'Add New PDF File', 'text-domain' ),
    'edit_item'          => esc_html__( 'Edit PDF File', 'text-domain' ),
    'new_item'           => esc_html__( 'New PDF File', 'text-domain' ),
    'all_items'          => esc_html__( 'All PDF Files', 'text-domain' ),
    'view_item'          => esc_html__( 'View PDF File', 'text-domain' ),
    'search_items'       => esc_html__( 'Search PDF Files', 'text-domain' ),
    'not_found'          => esc_html__( 'No PDF Files found', 'text-domain' ),
    'not_found_in_trash' => esc_html__( 'No PDF Files found in the Trash', 'text-domain' ), 
    'parent_item_colon'  => '',
    'menu_name'          => ' PDF Files'
  );
  $args = array(
    'labels'        => $labels,
    'description'   => 'Custom post for storing PDF files',
    'public'        => true,
    'publicly_queryable' => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
    'exclude_from_search' => false,
    'has_archive'   => true,
    'menu_icon'     => 'dashicons-carrot',
    'rewrite'       => array('slug' => 'pdf-file'),
  );
  register_post_type( 'pdf-files', $args ); 
}
add_action( 'init', 'create_custom_post_pdf' );
Need a helping hand in fixing your website issues?

If you are facing any problems in implementing these code snippets and tutorials, you can hire us to fix your website issues.

Hire Us