Crear Custom Post Types para Genesis Framework

Cómo crear un Custom Post Type lo puedes ver en este  post, pero si trabajamos con Genesis Framework, tendríamos que añadir unas características para que el nuevo CPT tenga todas las opciones, y virtudes, que da Genesis. Para ello hay que completar supports.

Para los que no queráis teclear código, recomiendo este plugin: Custom post type UI

Los supports de una instalación de Wp sin Gensis Framework:

'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),

Veamos pues, cómo podemos completarlo:

'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'genesis-cpt-archives-settings', 'genesis-seo', 'genesis-scripts', 'genesis-layouts', 'genesis-rel-autor',),

Cómo añadir las funciones de Genesis a un Custom Post Type

El código se tendrá que añadir en el function.php del child-theme. En este caso, al ser Genesis se puede usar el plugin Extender Custom o crear el directorio mu-plugins dentro de wp-content y, ahí crear nombre-de-nuestro-cpt.php donde añadiremos el código siguiente:

Si es un CPT de tercero valdría con añadir lo siguiente: add_post_type_support( ‘nombre_del_cpt’, array (‘genesis-cpt-archives-settings’, ‘genesis-seo’, ‘genesis-scripts’, ‘genesis-layouts’, ‘genesis-rel-autor’) );

Ejemplo CPT propio para Genesis

Plugin Name: CPT para Noticias
Plugin URI:
Description: Crear un CPT para un contenido tipo noticia.
Author: JYY
Author URI:
Version: 1.0.0
Text Domain: ypro-cpt-noticia
Domain Path: /

This code is a plugin to create a Custom Post Type in WordPress, it can be used with any WordPress theme.
The action initialises the function below it.
This example uses the term ‘Noticias’ as its name, a search and replace will allow any name to be used, making sure plural and singular versions of the name are replaced.
Also replace the name in ‘rewrite’ and in the ‘register_post_type’ function.
For non-Genesis themes the ‘genesis-cpt-archives-settings’ can be removed from the supports array.
To activate this as a plugin just add to wp-contents/plugins and activate in Dashboard

This doesn’t use all the labels and arguments possible but includes the main ones, you can see more here –

add_action( ‘init’, ‘ypro_noticias__create_custom_post_type’ );

function ypro_noticias__create_custom_post_type() {

    $labels = array(
        ‘name’               => __( ‘Noticia’ ),
        ‘singular_name’      => __( ‘Noticia’ ),
        ‘all_items’          => __( ‘Todas las Noticias’ ),
        ‘add_new’            => _x( ‘Añadir Noticia’, ‘Noticias’ ),
        ‘add_new_item’       => __( ‘Añadir Noticia’ ),
        ‘edit_item’          => __( ‘Editar Noticia’ ),
        ‘new_item’           => __( ‘Nueva Noticia’ ),
        ‘view_item’          => __( ‘Ver Noticia’ ),
        ‘search_items’       => __( ‘Buscar en Noticias’ ),
        ‘not_found’          => __( ‘No se han encontrado Noticias’ ),
        ‘not_found_in_trash’ => __( ‘No se han encontrado Noticias eliminadas’ ),
        ‘parent_item_colon’  => »
    $args = array(
        ‘labels’             => $labels,
        ‘public’             => true,
        ‘has_archive’        => true,
        ‘menu_icon’          => ‘dashicons-admin-users’, //pick one here ~>
        ‘rewrite’            => array( ‘slug’ => ‘noticia’ ),
        ‘taxonomies’         => array( ‘category’, ‘post_tag’ ),
        ‘query_var’          => true,
        ‘menu_position’      => 5,
        ‘supports’           => array( ‘genesis-cpt-archives-settings’, ‘thumbnail’ , ‘custom-fields’, ‘excerpt’, ‘comments’, ‘title’, ‘editor’)
    register_post_type( ‘noticia’, $args );

// flush the permalinks – ref –

function ypro_noticias__my_rewrite_flush() {
    // First, we «add» the custom post type via the above written function.
    // Note: «add» is written with quotes, as CPTs don’t get added to the DB,
    // They are only referenced in the post_type column with a post entry,
    // when you add a post of this CPT.

    // ATTENTION: This is *only* done during plugin activation hook in this example!
    // You should *NEVER EVER* do this on every page load!!
register_activation_hook( __FILE__, ‘ypro_noticias__my_rewrite_flush’ );