Last active
August 29, 2015 14:05
-
-
Save RupW/e85750191cd3c240855b to your computer and use it in GitHub Desktop.
WordPress theme snippet to warn if no permalink structure configured
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 | |
/** | |
* "We strongly recommend a permalink structure" admin site notice | |
* | |
* from http://wordpress.stackexchange.com/a/157071/3276 | |
*/ | |
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { | |
/* Admin-site only code */ | |
/** | |
* If we don't have a permalink structure configured, and if the user has | |
* permission to configure one, display a warning at the top of the admin | |
* site. (We can't yet test which screen we're on.) | |
*/ | |
if ( ( '' == get_option( 'permalink_structure' ) ) && | |
current_user_can( 'manage_options' ) ) { | |
/** | |
* If we're not already on the permalink configuration page, display a | |
* warning recommending the administrator configure one. | |
*/ | |
function wpse_157069_permalink_warning() { | |
$screen = get_current_screen(); | |
if ( ! isset( $screen ) || ( 'options-permalink' != $screen->id ) ) { | |
echo '<div id="permalink_warning" class="error">'; | |
echo '<p>' . sprintf( | |
__( 'We strongly recommend adding a %s to your site when using WPSE AwesomeTheme.' ), | |
sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'options-permalink.php' ) ), | |
__( 'permalink structure' ) ) ) . '</p>'; | |
echo '</div>'; | |
} | |
} | |
add_action( 'admin_footer', 'wpse_157069_permalink_warning' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment