![]() ![]() While this is not the best approach per se, it is until the ticket ( #16024) for this is resolved. Now, we don't need HTML conditional statements to conditionally link scripts or styles, and we can follow WordPress best practices to use wp_enqueue_script() and wp_enqueue_style(). Here I ensure that we have IE first via $is_IE, then I make the API call for further conditional testing. Instead WordPress has some built-in simple browser detection: So while I could have used wp_check_browser_version() to get the browser, it makes an external API call, which I prefer to avoid if possible. So for example, if we want to enqueue a script for browsers less than IE 9, we can do something like this: wpenqueuescripts is the proper hook to use when enqueuing scripts and styles that are meant to appear on the front end. While the WordPress dashboard focuses primarily on insecure and upgrade as the key to display Browser Nag Meta Box, we can use the function to get the name of the browser and the version. The versions returned are always those found in the About Browser (e.g. wpenqueuescript ( handle ,src ,deps ,ver ,infooter ) wpenqueuescripts, adminenqueuescripts, loginenqueuescripts. ![]() The names of the major browsers are as follows (of the ones I tested): You can use the adminenqueuescripts hook if you would like to enqueue a script into wp-admin. When you access the Browse Happy API ( $response = wp_check_browser_version() ), here is the basic response array: Array (
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |