Open DKGupta-git opened 1 year ago
<?php /**
// add_action('wp_enqueue_scripts', 'callback_for_setting_up_scripts'); // function callback_for_setting_up_scripts() { // wp_register_style( 'assets_css', 'http://locationofcss.com/mycss.css' ); // wp_enqueue_style( 'assets_css' ); // wp_enqueue_script( 'assets_js', 'http://locationofscript.com/myscript.js', array( 'jquery' ) ); // } include( plugin_dir_path( FILE ) . 'custom-post-type.php');
function your_namespace() { wp_register_style('assets_css', plugins_url('/assets/assets_css.css',FILE )); wp_enqueue_style('assets_css'); wp_register_script( 'assets_js', plugins_url('/assets/assets_js.js',FILE )); wp_enqueue_script('assets_js'); } add_action( 'admin_enqueue_scripts','your_namespace');
/**
@see register_post_type() for registering custom post types. */ function wpdocs_create_book_taxonomies() { // Add new taxonomy, make it hierarchical (like categories) $labels = array( 'name' => _x( 'Genres', 'taxonomy general name', 'textdomain' ), 'singular_name' => _x( 'Genre', 'taxonomy singular name', 'textdomain' ), 'search_items' => ( 'Search Genres', 'textdomain' ), 'all_items' => __( 'All Genres', 'textdomain' ), 'parent_item' => ( 'Parent Genre', 'textdomain' ), 'parent_item_colon' => ( 'Parent Genre:', 'textdomain' ), 'edit_item' => __( 'Edit Genre', 'textdomain' ), 'update_item' => ( 'Update Genre', 'textdomain' ), 'add_new_item' => ( 'Add New Genre', 'textdomain' ), 'new_item_name' => ( 'New Genre Name', 'textdomain' ), 'menu_name' => __( 'Genre', 'textdomain' ), );
$args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'genre' ), );
register_taxonomy( 'genre', array( 'news' ), $args );
unset( $args ); unset( $labels );
// Add new taxonomy, NOT hierarchical (like tags) $labels = array( 'name' => _x( 'Writers', 'taxonomy general name', 'textdomain' ), 'singular_name' => _x( 'Writer', 'taxonomy singular name', 'textdomain' ), 'search_items' => ( 'Search Writers', 'textdomain' ), 'popular_items' => __( 'Popular Writers', 'textdomain' ), 'all_items' => ( 'All Writers', 'textdomain' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => ( 'Edit Writer', 'textdomain' ), 'update_item' => ( 'Update Writer', 'textdomain' ), 'add_new_item' => ( 'Add New Writer', 'textdomain' ), 'new_item_name' => __( 'New Writer Name', 'textdomain' ), 'separate_items_with_commas' => ( 'Separate writers with commas', 'textdomain' ), 'add_or_remove_items' => ( 'Add or remove writers', 'textdomain' ), 'choose_from_most_used' => __( 'Choose from the most used writers', 'textdomain' ), 'not_found' => ( 'No writers found.', 'textdomain' ), 'menu_name' => __( 'Writers', 'textdomain' ), );
$args = array( 'hierarchical' => false, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array( 'slug' => 'writer' ), );
register_taxonomy( 'writer', 'news', $args ); } // hook into the init action and call create_book_taxonomies when it fires add_action( 'init', 'wpdocs_create_book_taxonomies', 0 );
<?php
/Custom Post type start/
function cw_post_type_news() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);
$labels = array(
'name' => _x('news', 'plural'),
'singular_name' => _x('news', 'singular'),
'menu_name' => _x('news', 'admin menu'),
'name_admin_bar' => _x('news', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New news'),
'new_item' => __('New news'),
'edit_item' => __('Edit news'),
'view_item' => __('View news'),
'all_items' => __('All news'),
'search_items' => __('Search news'),
'not_found' => __('No news found.'),
);
$args = array(
'supports' => $supports,
'labels' => $labels,
'public' => true,
'query_var' => true,
'menu_position' => 5,
'rewrite' => array('slug' => 'news'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('news', $args);
}
add_action('init', 'cw_post_type_news');
?>
// Hook
add_action('admin_menu', 'add_tutorial_cpt_submenu_example');
//admin_menu callback function
function add_tutorial_cpt_submenu_example(){
add_submenu_page(
'edit.php?post_type=tutorial', //$parent_slug
'Tutorial Subpage Example', //$page_title
'Tutorial Settings', //$menu_title
'manage_options', //$capability
'tutorial_subpage_example',//$menu_slug
'tutorial_subpage_example_render_page'//$function
);
}
//add_submenu_page callback function
function tutorial_subpage_example_render_page() {
echo '<h2> Tutorial Subpage Example </h2>';
}
https://developer.wordpress.org/reference/functions/register_taxonomy/