What’s the difference between WordPress random_int() and PHP built-in function random_int()?

WordPress is old. In fact, it is older than PHP7, in which PHP introduced random_int(). WP wanted/needed this functionality before, so another method was implemented. how does the PHP interpreter understand which of the two functions I’m calling? Good question. The interpreter doesn’t understand this. And hence, if you had PHP7 and would define this … Read more

Add container to nav_menu sub menu

Use a custom walker, extend the methods start_lvl() and end_lvl. Sample code, not tested: class WPSE_78121_Sublevel_Walker extends Walker_Nav_Menu { function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat(“\t”, $depth); $output .= “\n$indent<div class=”sub-menu-wrap”><ul class=”sub-menu”>\n”; } function end_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat(“\t”, $depth); … Read more

Excluding iPad from wp_is_mobile

t f’s answer got me thinking. Actually, I can use the core function and adapt it as I like but just put everything in a new function. So here goes: function my_wp_is_mobile() { static $is_mobile; if ( isset($is_mobile) ) return $is_mobile; if ( empty($_SERVER[‘HTTP_USER_AGENT’]) ) { $is_mobile = false; } elseif ( strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Android’) !== … Read more

Is there any global functions.php file which works for any theme?

The difference between theme and non-theme code is organizational rather than technical. Any code that is active contributes to resulting environment, does not matter where it is loaded from. There is number of places where code gets loaded from, which are not part of WordPress core: wp-config.php configuration file active theme (and its parent in … Read more