I created a custom post type for my blog, to allow easier separation of content. This new post type supports different post formats, but most of them will be galleries.
register_post_type('atelier',
array(
'label' => 'L'Atelier',
'public' => true,
'supports' => array('title', 'editor', 'post-formats')
)
);
I saw that it is possible in Settings -> Writing to set the default post format for posts, is it possible to do the same for my newly created post type?
One option would be to modify the global Default Post Format setting, via
Dashboard -> Settings -> Writing
.Note that this setting is global, so it would set the default for all post types that support Post Formats.
If you have no need of post formats for blog Posts, you could simply enable post-format support only for your custom post type, by removing post-format support for blog posts:
(Untested, but I see no reason why it shouldn’t work.)
You can handle this using the
option_default_post_format
filter:If you want to set up the filter for multiple custom post types, I’d edit the function to use a switch statement, like so:
For starters used to a different PHP syntax: The code blocks in @MichaelDozark’s excellent answer can also be written as:
And:
Source: Examples for the
switch
statement in the PHP Manual.