Function and usage of get_the_modified_author() in wordpress


Answers ( 1 )


    The get_the_modified_author() function in WordPress is used to retrieve the name of the author who last edited the current post. This is particularly useful in environments where multiple authors have the capability to edit posts, allowing for tracking of who made the most recent changes. Here's a detailed explanation and sample usage:

    Function Signature

    get_the_modified_author(): string|void


    • Purpose: To fetch the display name of the author who last modified the current post.
    • Return Type:
      • string: The display name of the author.
      • void: Returns nothing if the author's name is unknown or if the post has not been modified by another user after its initial publication.


    Basic Usage

    In a typical scenario, you can use get_the_modified_author() within the loop to display the name of the user who last edited the post.

    if ( have_posts() ) {
        while ( have_posts() ) {
            echo 'Last modified by: ' . get_the_modified_author();

    Checking for Unknown Author

    Since the function can return an empty string if the author is unknown, you might want to handle this case:

    $modified_author = get_the_modified_author();
    if ( !empty($modified_author) ) {
        echo 'Last modified by: ' . $modified_author;
    } else {
        echo 'Author unknown';

    Use in Custom Post Types

    get_the_modified_author() can also be used with custom post types. It works the same way as with standard posts:

    $args = array(
        'post_type' => 'your_custom_post_type',
        // Other arguments...
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            echo 'Last modified by: ' . get_the_modified_author();


    get_the_modified_author() is a simple yet powerful function in WordPress for tracking post modifications. It's especially useful in collaborative environments and can be used with any post type. Remember to handle cases where the author might be unknown to avoid displaying empty or misleading information.

Leave an answer