Here is my ammended version of your code:
<?php
if( is_ie() && get_browser_version() < 9 ) {
if ( is_active_sidebar( 'countdown-ie' ) ) {
dynamic_sidebar( 'countdown-ie' );
} else {
?>
<div class="pre-widget">
<p><strong>Widgetized area 1</strong></p>
<p>This panel is active and ready for you to add some widgets via the WP Admin</p>
</div>
<?php
}
} else {
if ( is_active_sidebar( 'countdown' ) ){
dynamic_sidebar ('countdown');
} else {
?>
<div class="pre-widget">
<p><strong>Widgetized area 2</strong></p>
<p>This panel is active and ready for you to add some widgets via the WP Admin</p>
</div>
<?php
}
}
Changelog:
- Your initial check now uses the
is_ie
andget_browser_version
functions - Fixed PHP tag spam. There’s no need to wrap every statement in PHP tags, it’s just extra effort to type out
- Switched to the original conditional syntax of
if () {} else {}
to simplify - Indented HTML
- Removed trailing spaces
- Fixed a broken closing PHP tag
? >
- dynamic_sidebar always exists, you should be checking if there are any widgets in that sidebar instead, so use
is_active_sidebar
- Some wordpress coding standards fixes
A final note
You shouldn’t be sniffing the user browser. This code will fail if you have caching enabled ( user 1 is on IE, page gets cached, user 2 is on firefox but sees cached IE page.. )