Skip to content

Instantly share code, notes, and snippets.

@hinnerk-a
Created January 3, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hinnerk-a/473ffd69277f3949a85a to your computer and use it in GitHub Desktop.
Save hinnerk-a/473ffd69277f3949a85a to your computer and use it in GitHub Desktop.
Postfix all occurrences of a trademark with ® (PHP function and optional WordPress hook)
/*
Author: Hinnerk Altenburg
Author URI: http://www.hinnerk-altenburg.de
Trademark: 'WP-ImmoMakler' is a registered trademark of Hinnerk Altenburg
Copyright: © 2015 Hinnerk Altenburg (mail@hinnerk-altenburg.de)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Corrects letter case of a given trademark and postfixes all occurrences of it with ®
*
* @param string $text The text to be filtered
* @param string $trademark The notation of the trademark in correct letter case
* @return string The filtered text
*/
function postfix_registered_trademark( $text, $trademark='WP-ImmoMakler' ) {
// Correct case
$text = str_ireplace( $trademark, $trademark, $text );
// Remove already attached ®'s to prevent double ®'s
$text = str_replace( $trademark . '®', $trademark, $text );
// Postfix a superscript ® to the trademark
$text = str_replace( $trademark, $trademark . '<sup>®</sup>', $text );
return $text;
}
// WordPress developers may now hook that function into the_content, the_title and comment_text to globally transform the trademark
add_filter( 'the_title', 'postfix_registered_trademark', 12 );
add_filter( 'the_content', 'postfix_registered_trademark', 12 );
add_filter( 'comment_text', 'postfix_registered_trademark', 32 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment