Home Forums WordPress created a custom plugin but custom post type is not appearing in admin panel on

Viewing 1 reply thread
  • Author
    Posts
    • #138
      sagar johari
      Participant

      I’ve been searching for correct reference to create a custom plugin but ended up getting different opinions and error in code…!
      please help.

    • #139
      avi
      Participant
      <?php
      /*
      Plugin Name: Custom Post Types
      Description: Add post types for custom articles
      Author: Hostinger Dev
      */
      // Hook ht_custom_post_custom_article() to the init action hook
      add_action( 'init', 'custom_post' );
      // The custom function to register a custom article post type
      function custom_post() {
      // Set the labels. This variable is used in the $args array
      $labels = array(
      'name' => __( 'Custom Articles' ),
      'singular_name' => __( 'Custom Article' ),
      'add_new' => __( 'Add New Custom Article' ),
      'add_new_item' => __( 'Add New Custom Article' ),
      'edit_item' => __( 'Edit Custom Article' ),
      'new_item' => __( 'New Custom Article' ),
      'all_items' => __( 'All Custom Articles' ),
      'view_item' => __( 'View Custom Article' ),
      'search_items' => __( 'Search Custom Article' ),
      'featured_image' => 'Poster',
      'set_featured_image' => 'Add Poster'
      );
      // The arguments for our post type, to be entered as parameter 2 of register_post_type()
      $args = array(
      'labels' => $labels,
      'description' => 'Holds our custom article post specific data',
      'public' => true,
      'menu_position' => 6,
      'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),
      'has_archive' => true,
      'show_in_admin_bar' => true,
      'show_in_nav_menus' => true,
      'query_var' => true,
      );
      // Call the actual WordPress function
      // Parameter 1 is a name for the post type
      // Parameter 2 is the $args array
      register_post_type('article', $args);
      }

      This may help…!

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
Scroll to Top