Use Transient to speed up WordPress

One of the features of WordPress is the ease of applying dropdown menus with access to posts & pages.

Applying menus in the header is a simply matter of including the following lines of code in header.php

‘items_wrap’ => ‘%3$s’,
‘depth’ => 3,
‘theme_location’ => ‘header-menu’,
‘container’ => false ));

However, this simple routine is pretty slow for complex or crowded menus and can result in a bottleneck as the page loads.
One solution is to cache the menus (which we presume chane infrequently), using WordPress’s “transient” command.

Effectively we test to see if we have a copy of the menu or whatever element in the cache.
If not, we add it to the cache, however if it does exist in the cache we grab it from there rather than creating it.

if(false === $cached_menu){         
      $cached_menu =  wp_nav_menu(array( ‘items_wrap’ => ‘%3$s’, ‘depth’ => 3, ‘theme_location’ => ‘header-menu’, ‘container’ => false, ‘echo’ => false ));                 
set_transient(‘the_header_menu’, $cached_menu, 3600*5);    

    echo $cached_menu; 


Modify the admin menu bar in WordPress

Recently we were asked by a client to simplify the presentation of the WordPress menu bar.

There are some nice plugins that you can use to achieve this such as “Admin Menu Editor Pro”.  This wonderful plugin offers lots of functionality, however, some of it’s best features are only available on the paid version of the site.

If you’re not in a position to buy a paid version, he is one way to manipulate the menu.
In this instance, the client had trouble remembering where to find the option to change the order of menu items on the front end of their site.  This is normally located at a submenu item of “appearance”.

We wanted to move it to the main menu so it would be easier to find  (less support for us).
So we added this routine to the “functions.php” file.

Please remember to back up this file before you every modify it, as even the slightest syntax error will cause your website to fail.

function change_menus_position() {

//   remove the menu item from the theme altogether
remove_submenu_page( ‘themes.php’, ‘nav-menus.php’ );

//  add it back to the main menu.


Displaying dates using PHP

tomorrow  = mktime(0, 0, 0, date(“m”)  , date(“d”)+1, date(“Y”));
last month = mktime(0, 0, 0, date(“m”)-1, date(“d”),   date(“Y”));
next year  = mktime(0, 0, 0, date(“m”),   date(“d”),   date(“Y”)+1);

Wednesday the 15th =  date(‘l \t\h\e jS’) 
Wednesday = date(“l”)

March 10, 2017 5:16 pm = date(“F j, Y, g:i a”);                
03.10.17 = date(“m.d.y”);                       
10, 3, 2017 = date(“j, n, Y”);                      
 20170310 = date(“Ymd”);