Add Developer Branding
Overview
Add lightweight developer branding to the frontend and WordPress admin.
The snippet outputs a frontend HTML comment in wp_head, replaces the left admin footer text with a linked credit, and removes the WordPress version text from the right admin footer. Customize the author, company, and URL in the branding helper or OOP constants.
Variants
- Procedural
- OOP
<?php
/**
* Add frontend and admin developer branding.
*/
/**
* Branding data.
*
* @return array{author: string, company: string, url: string}
*/
if ( ! function_exists( 'mac_get_branding_data' ) ) {
function mac_get_branding_data(): array {
return [
'author' => 'Mihai Circea',
'company' => 'All Phase Media',
'url' => 'https://allphasemedia.com',
];
}
}
/**
* Frontend branding comment.
*/
if ( ! function_exists( 'mac_output_frontend_branding_comment' ) ) {
function mac_output_frontend_branding_comment(): void {
$branding = mac_get_branding_data();
$comment = sprintf(
'Built by %s @ %s %s',
$branding['author'],
$branding['company'],
$branding['url']
);
echo "\n<!-- " . esc_html( $comment ) . " -->\n";
}
}
add_action( 'wp_head', 'mac_output_frontend_branding_comment', 0 );
/**
* Admin footer text (left side).
*/
if ( ! function_exists( 'mac_filter_admin_footer_branding' ) ) {
function mac_filter_admin_footer_branding( ?string $text ): string {
$branding = mac_get_branding_data();
return sprintf(
'Built by %s @ <a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
esc_html( $branding['author'] ),
esc_url( $branding['url'] ),
esc_html( $branding['company'] )
);
}
}
add_filter(
'admin_footer_text',
'mac_filter_admin_footer_branding',
999
);
/**
* Remove WP version text (right side).
*/
add_filter( 'update_footer', '__return_empty_string', 999 );
<?php
/**
* Apply frontend and admin branding.
*
* @package mac-core
*/
declare(strict_types=1);
namespace MacCore\Services\Core;
use MacCore\Contracts\Service;
final class AddDeveloperBranding implements Service
{
private const AUTHOR = 'Mihai Circea';
private const COMPANY = 'All Phase Media';
private const URL = 'https://allphasemedia.com';
public function register(): void
{
\add_action(
'wp_head',
[$this, 'output_frontend_comment'],
0
);
\add_filter(
'admin_footer_text',
[$this, 'filter_admin_footer_text'],
999,
1
);
\add_filter(
'update_footer',
[$this, 'remove_update_footer_text'],
999,
1
);
}
public function output_frontend_comment(): void
{
$comment = sprintf(
'Built by %s @ %s %s',
self::AUTHOR,
self::COMPANY,
self::URL
);
echo "\n<!-- " . \esc_html( $comment ) . " -->\n";
}
public function filter_admin_footer_text( ?string $text ): string
{
$author = \esc_html( self::AUTHOR );
$company = sprintf(
'<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
\esc_url( self::URL ),
\esc_html( self::COMPANY )
);
return sprintf(
'Built by %s @ %s',
$author,
$company
);
}
public function remove_update_footer_text( ?string $text ): string
{
return '';
}
}