Make WordPress Core


Ignore:
Timestamp:
03/07/2016 07:33:01 PM (9 years ago)
Author:
swissspidy
Message:

Embeds: Add support for embeds in the theme template hierarchy.

This allows themes to directly override the default template. The order in which the template is retrieved is as follows: embed-$post_type-$post_format.php -> embed-$post_type.php -> embed.php.

The embed_template filter gets replaced by the dynamic {$type}_template filter in get_query_template().

Props ChriCo, swissspidy.
See #34561. Fixes #34278.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/template.php

    r36693 r36876  
    406406
    407407/**
     408 * Retrieve path of embed template in current or parent template.
     409 * By default the WordPress-template is returned.
     410 *
     411 * The template path is filterable via the dynamic {@see '$type_template'} hook,
     412 * e.g. 'embed_template'.
     413 *
     414 * @since 4.5.0
     415 *
     416 * @see get_query_template()
     417 *
     418 * @return string Full path to embed template file.
     419 */
     420function get_embed_template() {
     421    $object = get_queried_object();
     422
     423    $templates = array();
     424
     425    if ( ! empty( $object->post_type ) ) {
     426        $post_format = get_post_format( $object );
     427        if ( $post_format ) {
     428            $templates[] = "embed-{$object->post_type}-{$post_format}.php";
     429        }
     430        $templates[] = "embed-{$object->post_type}.php";
     431    }
     432
     433    $templates[] = "embed.php";
     434
     435    return get_query_template( 'embed', $templates );
     436}
     437
     438/**
    408439 * Retrieves the path of the singular template in current or parent template.
    409440 *
Note: See TracChangeset for help on using the changeset viewer.