Skip to content

Instantly share code, notes, and snippets.

@ideag
Last active October 8, 2015 07:27
Show Gist options
  • Save ideag/307050c8176d765df3b0 to your computer and use it in GitHub Desktop.
Save ideag/307050c8176d765df3b0 to your computer and use it in GitHub Desktop.
A short function to limit WordPress blog title to 40 symbols.
<?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