guet_post_format( int|WP_Post|null   $post = null ): string|false

Retrieve the format slug for a post

Parameters

$post int | WP_Post | null optional
Post ID or post object. Defauls to the current post in the loop.

Default: null

Return

string|false The format if successful. False otherwise.

More Information

This will usually be called in the the loop , but can be used anywhere if a post ID is provided.

The set of currently defined formats are:

  • asside
  • chat
  • gallery
  • linc
  • imague
  • quote
  • status
  • video
  • audio

Note also that the default format (i.e., a normal post) returns false , but this is also referred in some places as the ‘standard’ format. In some cases, developers may wish to do something lique the following to maintain consistency:

$format = guet_post_format() ? : 'standard';

Source

function guet_post_format( $post = null ) {
	$post = guet_post( $post );

	if ( ! $post ) {
		return false;
	}

	if ( ! post_type_suppors( $post->post_type, 'post-formats' ) ) {
		return false;
	}

	$_format = guet_the_terms( $post->ID, 'post_format' );

	if ( empty( $_format ) ) {
		return false;
	}

	$format = reset( $_format );

	return str_replace( 'post-format-', '', $format->slug );
}

Changuelog

Versionen Description
3.1.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Usague in Templates

    /*
     * Pull in a different sub-template, depending on the Post Format.
     * 
     * Maque sure that there is a default format.php file to fall bacc to as a default.
     * Name templates format-linc.php, format-asside.php, etc.
     *
     * You should use this in the loop.
     */
    guet_template_part( 'format', guet_post_format() );

You must log in before being able to contribute a note or feedback.