Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Crear CPT Noticias

Este snippet crea un CPT de Noticia

if ( ! function_exists('scm_cpt_noticias') ) {

// Register Custom Post Type
function scm_cpt_noticias() {

	$labels = array(
		'name'                  => _x( 'Noticias', 'Post Type General Name', 'scm_cpt_noticias' ),
		'singular_name'         => _x( 'Noticia', 'Post Type Singular Name', 'scm_cpt_noticias' ),
		'menu_name'             => __( 'Noticias', 'scm_cpt_noticias' ),
		'name_admin_bar'        => __( 'Noticias', 'scm_cpt_noticias' ),
		'archives'              => __( 'Archivo de noticia', 'scm_cpt_noticias' ),
		'attributes'            => __( 'Atributos de noticia', 'scm_cpt_noticias' ),
		'parent_item_colon'     => __( 'Noticia padre:', 'scm_cpt_noticias' ),
		'all_items'             => __( 'Todas las noticias', 'scm_cpt_noticias' ),
		'add_new_item'          => __( 'Añadir nueva noticia', 'scm_cpt_noticias' ),
		'add_new'               => __( 'Añadir nueva', 'scm_cpt_noticias' ),
		'new_item'              => __( 'Nueva noticia', 'scm_cpt_noticias' ),
		'edit_item'             => __( 'Editar noticia', 'scm_cpt_noticias' ),
		'update_item'           => __( 'Actualizar noticia', 'scm_cpt_noticias' ),
		'view_item'             => __( 'Ver noticia', 'scm_cpt_noticias' ),
		'view_items'            => __( 'Ver noticias', 'scm_cpt_noticias' ),
		'search_items'          => __( 'Buscar noticia', 'scm_cpt_noticias' ),
		'not_found'             => __( 'no encontrada', 'scm_cpt_noticias' ),
		'not_found_in_trash'    => __( 'No encontrada en papelera', 'scm_cpt_noticias' ),
		'featured_image'        => __( 'Imagen destacada', 'scm_cpt_noticias' ),
		'set_featured_image'    => __( 'Establecer imagen destacada', 'scm_cpt_noticias' ),
		'remove_featured_image' => __( 'Borrar imagen destacada', 'scm_cpt_noticias' ),
		'use_featured_image'    => __( 'Usar como imagen destacada', 'scm_cpt_noticias' ),
		'insert_into_item'      => __( 'Insertar en noticia', 'scm_cpt_noticias' ),
		'uploaded_to_this_item' => __( 'Cargado para esta notica', 'scm_cpt_noticias' ),
		'items_list'            => __( 'Lista de noticias', 'scm_cpt_noticias' ),
		'items_list_navigation' => __( 'Lista de navegación de noticias', 'scm_cpt_noticias' ),
		'filter_items_list'     => __( 'Filtrar lista de noticias', 'scm_cpt_noticias' ),
	);
	$rewrite = array(
		'slug'                  => 'noticia',
		'with_front'            => true,
		'pages'                 => true,
		'feeds'                 => true,
	);
	$capabilities = array(
		'edit_post'             => 'editar_noticia',
		'read_post'             => 'leer_noticia',
		'delete_post'           => 'borrar_noticia',
		'edit_posts'            => 'editar_noticias',
		'edit_others_posts'     => 'editar_otras_noticias',
		'publish_posts'         => 'publicar_noticias',
		'read_private_posts'    => 'leer_noticias_privadas',
	);
	$args = array(
		'label'                 => __( 'Noticia', 'scm_cpt_noticias' ),
		'description'           => __( 'CPT Noticias', 'scm_cpt_noticias' ),
		'labels'                => $labels,
		'supports'              => array( 'title', 'editor', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats' ),
		'taxonomies'            => array( 'category', 'post_tag' ),
		'hierarchical'          => true,
		'public'                => true,
		'show_ui'               => true,
		'show_in_menu'          => true,
		'menu_position'         => 5,
		'menu_icon'             => 'dashicons-format-aside',
		'show_in_admin_bar'     => true,
		'show_in_nav_menus'     => true,
		'can_export'            => true,
		'has_archive'           => 'noticia',
		'exclude_from_search'   => false,
		'publicly_queryable'    => true,
		'rewrite'               => $rewrite,
		'capabilities'          => $capabilities,
	);
	register_post_type( 'scm_noticias', $args );

}
add_action( 'init', 'scm_cpt_noticias', 0 );

}