Last active
October 8, 2015 07:27
-
-
Save ideag/307050c8176d765df3b0 to your computer and use it in GitHub Desktop.
A short function to limit WordPress blog title to 40 symbols.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'pre_update_option_blogname', 'arunas_limit_blogname', 10, 2 ); | |
function arunas_limit_blogname( $value, $old_value ) { | |
// check for length (pr do any other kind of validation) | |
if ( 40 < strlen($value) ) { | |
// throw error via Settings API | |
add_settings_error( | |
'blogname', // option name | |
'blogname', // error id | |
__( 'Blog title is too long', 'plugin-slug' ), | |
'error' // error type | |
); | |
// short-circuit `update_option` to prevent new title from being saved | |
$value = $old_value; | |
} | |
return $value; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment