Rejestracja custom post

dodanie custom post type w pliku function.php a najlepiej w osobnym pliku custom-posts.php który podpinamy do function.php poprzez:


include_once 'lib/custom-functions.php';

 


// create Logotypes section in admin menu
add_action( 'init', 'create_logos' );
function create_logos() {
    register_post_type( 'logos',
        array(
            'labels' => array(
                'name' => 'Logotypy',
                'singular_name' => 'Logotyp',
                'add_new' => 'Dodaj Logotyp',
                'add_new_item' => 'Dodaj Logotyp',
                'edit' => 'Edytuj',
                'edit_item' => 'Edytuj Logotyp',
                'new_item' => 'Nowy Logotyp',
                'view' => 'Pokaż',
                'view_item' => 'Pokaż Logotyp',
                'search_items' => 'Wyszukaj Logotyp',
                'not_found' => 'Nie znaleziono Logotypu',
                'not_found_in_trash' => 'Brak Logotypu w Koszu',
                'parent' => 'Rodzic Logotypu'
            ),

            'public' => true,
            'menu_position' => 11,
            'hierarchical'=>true,
            'query_var' => false, 
            'supports' => array( 'title','editor','revisions'),
            'menu_icon' => 'dashicons-carrot',
            'has_archive' => false,
            'exclude_from_search' => true,
            'publicly_queryable' => false,
            'show_in_nav_menus' => false,
            'show_ui' => false,
            'taxonomies' => array( '' ),
            'rewrite' => array( 'slug' => 'book' )
        )
    );
}

lub w skróconej wersji, z dodaniem koloru do dodanej ikony:


add_action( 'init', 'create_opinie' );
function create_opinie() {
  register_post_type( 'testimonials',
    array(
      'labels' => array(
        'name' => __( 'Testimonials' ),
        'singular_name' => __( 'Testimonial' )
      ),
      'public' => true,
      'has_archive' => true,
      'menu_position' => 11,
      'supports' => array( 'title','editor','revisions'),
      'menu_icon' => 'dashicons-format-chat',
    )
  );
}

//add style color icon
add_action('admin_head', 'my_custom_colors');
function my_custom_colors() {
  echo '<style>
    #adminmenu div.wp-menu-image.dashicons-format-chat:before {
      color: #005590;
    }
  </style>';
}

gdzie:

  • query_var – wyszukiwanie w liście postów
  • menu_icon – ikona menu
  • exclude_from_search – wykluczenie z wyników wyszukiwania
  • show_in_nav_menus – wyświetlenie w widoku menu
  • show_ui – wyświetlenie w admin menu

 

Default: bottom of menu structure

  • 2 – Dashboard
  • 4 – Separator
  • 5 – Posts
  • 10 – Media
  • 15 – Links
  • 20 – Pages
  • 25 – Comments
  • 59 – Separator
  • 60 – Appearance
  • 65 – Plugins
  • 70 – Users
  • 75 – Tools
  • 80 – Settings
  • 99 – Separator

For the Network Admin menu, the values are different

  • 2 – Dashboard
  • 4 – Separator
  • 5 – Sites
  • 10 – Users
  • 15 – Themes
  • 20 – Plugins
  • 25 – Settings
  • 30 – Updates
  • 99 – Separator