Skip to content

Instantly share code, notes, and snippets.

@tankbar
Forked from gregrickaby/functions.php
Created January 24, 2017 07:51
Show Gist options
  • Save tankbar/5b60df1939fc117dedfbc713cc444fca to your computer and use it in GitHub Desktop.
Save tankbar/5b60df1939fc117dedfbc713cc444fca to your computer and use it in GitHub Desktop.
Filter a custom post type after it's been registered
<?php
/**
* Filter the Products CPT to register more options.
*
* @param $args array The original CPT args.
* @param $post_type string The CPT slug.
*
* @return array
*/
function wds_client_filter_products_cpt( $args, $post_type ) {
// If not Products CPT, bail.
if ( 'products' !== $post_type ) {
return $args;
}
// Add additional Products CPT options.
$products_args = array(
'has_archive' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields', 'page-attributes' ),
);
// Merge args together.
return array_merge( $args, $product_args );
}
add_filter( 'register_post_type_args', 'wds_client_filter_products_cpt', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment