Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Probably best to refer to this question/answer. wordpress.stackexchange.com/questions/32480/… Basically, create a custom post type template and just style them through that. –  Chetan Jan 23 '12 at 18:55

3 Answers 3

up vote 3 down vote accepted

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:

<?php
remove_post_type_support( 'post', 'post-formats' );
?>

(Untested, but I see no reason why it shouldn't work.)

share|improve this answer

You can handle this using the option_default_post_format filter:

add_filter( 'option_default_post_format', 'slimline_default_post_format' );

/**
 * Posts of post_type_1 will be asides by default, but all other post types
 * will be the default set on the Settings > Writing admin panel
 */
function slimline_default_post_format( $format ) {
    global $post_type;

    return ( 'post_type_1' === $post_type ? 'aside' : $format );
}

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:

function slimline_default_post_format( $format ) {
    global $post_type;

    switch( $post_type ) {
        case 'post_type_1' :
            $format = 'aside';
            break;
        case 'post_type_2' :
            $format = 'quote';
            break;
    }

    return $format;
}
share|improve this answer
    
This answer actually addresses the original question! –  somatic Sep 11 '13 at 21:10

For starters used to a different PHP syntax: The code blocks in @MichaelDozark's excellent answer can also be written as:

/*
 * Posts of post_type_1 will be asides by default, but all other post types
 * will be the default set on the Settings > Writing admin panel
 */
add_filter( 'option_default_post_format', 'custom_default_post_format' );
function custom_default_post_format( $format ) {
    global $post_type;

    if( $post_type == 'post_type_1' ) {
        $format = 'aside';
    }

    return $format;
}

And:

add_filter( 'option_default_post_format', 'custom_default_post_format' );
function custom_default_post_format( $format ) {
    global $post_type;

    if( $post_type == 'post_type_1' ) {
        $format = 'aside';
    } elseif ( $post_type == 'post_type_2' ) {
        $format = 'quote';
    }

    return $format;
}

Source: Examples for the switch statement in the PHP Manual.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.