Halloween Sale 15% off Ends in See the plans
PHP

Serve a humans.txt File

Answers /humans.txt with a plain-text file crediting the people and tools behind the site, generated by WordPress so you do not need to upload anything to the server.

Don’t have WPIDE yet? Install it on your site

Code

// File contents.
$wpide_humans_txt = "/* TEAM */\nDeveloper: Jane Doe\nContact: [email protected]\nLocation: Lisbon, Portugal\n\n/* SITE */\nStandards: HTML5, CSS3\nSoftware: WordPress";

add_action( 'init', function () {
    add_rewrite_rule( '^humans\.txt$', 'index.php?wpide_humans=1', 'top' );
} );

add_filter( 'query_vars', function ( $vars ) {
    $vars[] = 'wpide_humans';
    return $vars;
} );

add_action( 'template_redirect', function () use ( $wpide_humans_txt ) {
    if ( ! get_query_var( 'wpide_humans' ) ) {
        return;
    }

    header( 'Content-Type: text/plain; charset=utf-8' );
    header( 'X-Robots-Tag: noindex' );
    echo wp_strip_all_tags( $wpide_humans_txt ) . "\n\n/* UPDATED */\nLast update: " . esc_html( mysql2date( 'Y/m/d', get_lastpostmodified( 'blog' ) ) ) . "\n";
    exit;
} );

Notes

Edit $wpide_humans_txt; save Settings > Permalinks once so WordPress learns the new address. A real humans.txt file on the server takes priority.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.