• I’ve historically created an “Articles” custom post type, which is essentially a very stripped down version of the default “post” post type (removed tags, comments, etc). I’ve done this for two primary reasons:

    -The URL being example.com/articles/my-article
    -Removing extensive functionality and clutter I’m not using (I don’t need / want category / tag archives, tags in general, revisions, trackbacks, etc)

    While the removal of these features may sound odd to many, just roll with me (or if you’d consider yourself an advanced user, try to sway me). That being said, rather than create a new Custom Post type of “Articles” (and hide the original “post” post type), I’d rather edit the existing “post” post type to strip it down.

    I’ve read some older articles mentioning use of register_post_type_args, using filters, etc, but none of it seemed up to date or conclusive on if those work on default types, and not just custom post types. If anyone could point me in the right direction on how to redefine the default post type (remove the above), add a rewrite slug, and more, I’d appreciate it!

Viewing 2 replies - 1 through 2 (of 2 total)
  • They’re all run through register_post_type() which runs it’s args through the register_post_type_args filter hook. You could do something like this:

    /**
     * Modify the 'post' post type upon registration
     * 
     * @param Array $args
     * @param String $post_type
     * 
     * @return Array $args
     */
    function prefix_modify_builtin_post_args( $args, $post_type ) {
    
    	if( 'post' == $post_type ) {
    
    		// Display a list of post registration arguments
    		printf( '<pre>%1$s</pre>', print_r( $args, 1 ) );
    		die(); // Kill page
    
    	}
    
        return $args;
    
    }
    add_filter( 'register_post_type_args', 'prefix_modify_builtin_post_args', 10, 2 );

    The above will prevent your website from loading ( so run it locally ) but will also display a formatted list of what the $args variable holds. Here you can change the labels and what the post type supports, etc.

    Something like

    $args['labels'] = array( 'singular_name' => __( 'Article' ) );

    Thread Starter Gemfruit

    (@gemfruit)

    That looks like exactly what I need. I’m currently only running a local setup using Vagrant and a custom theme using the Genesis framework, so no harm running that code.

    I found this article here – https://gregrickaby.com/2016/06/modify-wordpress-custom-post-type/

    The author is doing something very similar to what you’re suggesting, but I noticed at the bottom that it uses a function to merge the arrays – how does that work? If the new array values change what’s in “supports”, or has a different rewrite (say, to an existing CPT already using a rewrite), which is used? Just want to make sure I understand why I would merge (vs just completely rewrite everything, if that’s how it works), and which values are used if I do merge.

    Thanks again for pointing me in the right direction! I usually have a lot of trouble finding information on more advanced issues like this (although it’s been years since I’ve asked), so I appreciate it a lot.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Customizing Default “Post” Post Type’ is closed to new replies.