The answers you want are in the code. Meaning, you need to go exploring.
Your search should start with wp-includes/template-loader.php
. This is the very last file WordPress includes before the theme get’s loaded. it runs through a bunch of conditionals to check which type of page we’re out and what template to fetch.
The relevant (offending?) line:
<?php
elseif ( is_single() && $template = get_single_template() ) :
Now that we know get_single_template
fetches templates for single posts, we can go find that function in wp-includes/template.php
.
<?php
/**
* Retrieve path of single template in current or parent template.
*
* @since 1.5.0
*
* @return string
*/
function get_single_template() {
$object = get_queried_object();
$templates = array();
$templates[] = "single-{$object->post_type}.php";
$templates[] = "single.php";
return get_query_template( 'single', $templates );
}
No filters yet, but you’re starting to see how WP locates templates. Now we need to see what get_query_template
does (get_query_template
is also in wp-includes/template.php
).
<?php
/**
* Retrieve path to a template
*
* Used to quickly retrieve the path of a template without including the file
* extension. It will also check the parent theme, if the file exists, with
* the use of {@link locate_template()}. Allows for more generic template location
* without the use of the other get_*_template() functions.
*
* @since 1.5.0
*
* @param string $type Filename without extension.
* @param array $templates An optional list of template candidates
* @return string Full path to file.
*/
function get_query_template( $type, $templates = array() ) {
$type = preg_replace( '|[^a-z0-9-]+|', '', $type );
if ( empty( $templates ) )
$templates = array("{$type}.php");
return apply_filters( "{$type}_template", locate_template( $templates ) );
}
The first argument is the type of template we’re goign to be locating (single
for this question) and the second is a series of templates to search. This is the point where we stop. locate_template
just searches the child and parent theme directories for each of the files in the $templates
array — it returns the file path if one is found or an empty string if it isn’t.
Notice that $type
in this function is “single”.
I wrote all the above, so I could tell you that the filter is still single_template
. The actual string single_template
is not found in the source, but the filter still exists (and it works).