Using WordPress ‘get_author_template()’ PHP function

The get_author_template() WordPress PHP function retrieves the path of the author template in the current or parent template.

Usage

$template = get_author_template();

Parameters

  • None

More information

See WordPress Developer Resources: get_author_template()

Examples

Display Author Template for the Current Author

$template = get_author_template();
load_template($template);

Filter Author Template Hierarchy

add_filter('author_template_hierarchy', 'my_custom_author_template');

function my_custom_author_template($templates) {
    array_unshift($templates, 'custom-author.php');
    return $templates;
}

Redirect to Custom Author Template

add_action('template_redirect', 'redirect_to_custom_author_template');

function redirect_to_custom_author_template() {
    if (is_author()) {
        $custom_template = locate_template('custom-author.php');
        if ($custom_template) {
            load_template($custom_template);
            exit;
        }
    }
}

Create a Custom Function to Retrieve Author Template

function my_get_author_template() {
    $template = get_author_template();
    return apply_filters('my_get_author_template', $template);
}

Override Author Template Path

add_filter('author_template', 'override_author_template');

function override_author_template($template) {
    $custom_template = locate_template('my-author.php');
    return $custom_template ? $custom_template : $template;
}