How to modify footer in admin screen
Sometimes you may want to add your own footer text in admin screen. I use it often to add information about my theme. Of course it is visible only in admin screen, so you do not need to worry about WordPress regulation about asking user to view any copyright notice for common users.
How to do that? It’s very easy, we need to use admin_footer_text
filter.
1 2 3 4 |
add_filter( 'admin_footer_text', 'phylax_admin_footer_text' ); function phylax_admin_footer_text( $msg ) { $msg = 'Our Theme ©2016 <a href="http://example.com">Our team</a>'; } |
So, this is the simplest solution. We’ve got more here. I think we should leave original WordPress copyright, because it is just fair. To do that, just preserve original $msg
variable, like this:
1 2 3 4 |
add_filter( 'admin_footer_text', 'phylax_admin_footer_text' ); function phylax_admin_footer_text( $msg ) { $msg = 'Our Theme ©2016 <a href="http://example.com">Our team</a> | ' . $msg; } |
You may notice, that the footer string is in span
element (with ID footer-thankyou
). We may get into this span
element, but you must remember that it may change in the future. I use something like that:
1 2 3 4 5 6 7 8 9 10 11 |
add_filter( 'admin_footer_text', 'phylax_admin_footer_text' ); function phylax_admin_footer_text( $msg ) { $span = '<span id="footer-thankyou">'; $lukasz = 'Our Theme ©2016 <a href="http://example.com">Our team</a> | '; if ( strpos( $msg, $span ) !== false ) { $msg = str_replace( $span, $span . $lukasz , $msg ); } else { $msg = $lukasz . $msg; } return $msg; } |
And this should work even if they change span
element in the future. All right, this may be the end, but there is one more thing.
How to recognize admin screen?
Yeah. We may use our footer only on certain admin screens. This method will not work on every admin screen (like customizer for example) so it isn’t very clever thing to use it after is_admin()
function. It is stated in the WordPress documentation. But it is safe to use on every admin_footer_text
filter call. We do not have footer text in customizer as you may see 🙂
Last thing – $screen
variable is an object, so you must use it as an object, not as a string. Do some tests with this code:
1 2 3 4 5 6 7 8 9 10 11 12 |
add_filter( 'admin_footer_text', 'phylax_admin_footer_text' ); function phylax_admin_footer_text( $msg ) { $screen = get_current_screen(); $span = '<span id="footer-thankyou">'; $lukasz = 'Curren screen: ' . $screen->id . ' '; if ( strpos( $msg, $span ) !== false ) { $msg = str_replace( $span, $span . $lukasz , $msg ); } else { $msg = $lukasz . $msg; } return $msg; } |