Updated code to work with wp version >= 3.9