How to Create a Custom WordPress Post Type for Videos
To create a custom post type in WordPress named 'video' with the labels 'ویدیو', you can use the following code:
// Add custom post type 'video'
function create_video_post_type() {
$labels = array(
'name' => __( 'ویدیو', 'text-domain' ),
'singular_name' => __( 'ویدیو', 'text-domain' ),
'menu_name' => __( 'ویدیو', 'text-domain' ),
'name_admin_bar' => __( 'ویدیو', 'text-domain' ),
'add_new' => __( 'Add New', 'text-domain' ),
'add_new_item' => __( 'Add New ویدیو', 'text-domain' ),
'new_item' => __( 'New ویدیو', 'text-domain' ),
'edit_item' => __( 'Edit ویدیو', 'text-domain' ),
'view_item' => __( 'View ویدیو', 'text-domain' ),
'all_items' => __( 'All ویدیو', 'text-domain' ),
'search_items' => __( 'Search ویدیو', 'text-domain' ),
'parent_item_colon' => __( 'Parent ویدیو:', 'text-domain' ),
'not_found' => __( 'No ویدیو found.', 'text-domain' ),
'not_found_in_trash' => __( 'No ویدیو found in Trash.', 'text-domain' )
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'video' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail' )
);
register_post_type( 'video', $args );
}
add_action( 'init', 'create_video_post_type' );
You can add this code to your theme's functions.php file or create a custom plugin.
After adding the code, you will need to visit the WordPress admin area and go to Settings > Permalinks to flush the rewrite rules for the custom post type to take effect.
原文地址: https://www.cveoy.top/t/topic/n28c 著作权归作者所有。请勿转载和采集!