Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Last active July 29, 2025 08:02
Show Gist options
  • Select an option

  • Save mrchrisadams/a0c07b323d214a5f90596638ea495342 to your computer and use it in GitHub Desktop.

Select an option

Save mrchrisadams/a0c07b323d214a5f90596638ea495342 to your computer and use it in GitHub Desktop.
This is an example wordpress plugin to add carbon.txt headers into wordpress.

What's this?

This is is an minimal wordpress plugin we would need to allow any WordPress site to link to a carbon.txt file we would need to set up linked domains to work with the Green Web Platform.

How would it need to work?

  1. Install this plugin
  2. Activate the plugin
  3. Set the location of the carbon.txt file (see the screenshot)
  4. Check your site with the green web linked domains checking process to register it.

How do we make the plugin available?

Users can upload the single in this gist aboove, but we'd likely want a nicer experience. Either we publish this plugin ourselves to WP.org, or work with an existing group on a related green webby plugin so they include it in their code base, making use of their exiting audience. Or we provide guidance on hosting providers how to include it in their default stack of already activated plugins.

<?php
/*
Plugin Name: Carbon.txt Header Plugin
Description: Adds a carbon.txt header to HTTP responses for WordPress. Activate the plugin, enter where online the carbon.txt you want to refer to, and you're done!
Version: 1.0
Author: Chris Adams
*/
// Add admin menu
add_action('admin_menu', 'custom_header_plugin_menu');
function custom_header_plugin_menu() {
add_options_page(
'Custom Header Settings',
'Custom Header',
'manage_options',
'custom-header-settings',
'custom_header_plugin_options'
);
}
// Admin page content
function custom_header_plugin_options() {
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
// Save settings
if (isset($_POST['custom_header_url'])) {
update_option('custom_header_url', sanitize_text_field($_POST['custom_header_url']));
echo '<div class="notice notice-success"><p>Settings saved!</p></div>';
}
// Get current setting
$current_url = get_option('custom_header_url', 'https://www.timshostingprovider.com');
?>
<div class="wrap">
<h1>Custom Header Settings</h1>
<form method="post" action="">
<table class="form-table">
<tr>
<th scope="row"><label for="custom_header_url">Header URL</label></th>
<td>
<input type="text" name="custom_header_url" id="custom_header_url"
value="<?php echo esc_attr($current_url); ?>" class="regular-text" required>
<p class="description">Enter the URL for the CarbonTxt-Location header</p>
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Add custom header to responses
add_action('send_headers', 'add_custom_response_header');
function add_custom_response_header() {
$header_url = get_option('custom_header_url', 'https://www.timshostingprovider.com');
header("CarbonTxt-Location: $header_url");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment