0

After adding support for a selection of post formats like this:

add_theme_support( 'post-formats', array( 'aside', 'video' ) );

how can I then get the list of supported post formats back?

I'm building a theme where the user can toggle support for postformat, and I want other admin elements to reflect what post formats the user has configured the theme to support.

so I'm looking for something like

current_theme_supports( 'post-formats'); // outputs boolean

but that outputs just true or false, whereas I want to get an array of the post formats actually registered..

what would be the correct WordPress function to call (or constant/global var) to look at for this?

I want something like this:

get_supported_post_formats(); // out: array('aside', 'video')
5

Taken from post_format_meta_box;

if ( current_theme_supports( 'post-formats' ) ) {
    $post_formats = get_theme_support( 'post-formats' );

    if ( is_array( $post_formats[0] ) ) {
        print_r( $post_formats[0] );
        // Array( supported_format_1, supported_format_2 ... )
    }
}
2

get_theme_support( 'post-formats' ) will return the array of supported formats.

  • For some reason the array returned is nested, why is that? $post_formats[0] is the only parent key, so why is it there? – mikkelbreum Jun 30 '11 at 16:36
0

You can do array_shift to avoid the 0th element.

$temp = get_theme_support( 'post-formats' );
var_dump(array_shift( $temp ));

if you need it by key value pair, then

$temp = get_theme_support( 'post-formats' );
$ar = array_shift( $temp );
$ar = array_combine($ar, $ar);
var_dump($ar);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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