Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created January 21, 2013 03:09
Show Gist options
  • Select an option

  • Save GaryJones/4583367 to your computer and use it in GitHub Desktop.

Select an option

Save GaryJones/4583367 to your computer and use it in GitHub Desktop.
Add date menu item to end of existing menu items (in primary location).
<?php
add_filter( 'wp_nav_menu_items', 'gmj_add_date_menu_item', 10, 2 );
/**
* Add date menu item to end of existing menu items.
*
* @author Gary Jones
*
* @param string $items Menu items already converted to a string of markup.
* @args stdClass $args Menu arguments.
*
* @return string Amended markup.
*/
function gmj_add_date_menu_item( $items, stdClass $args ) {
// Limit to a certain menu location
if ( 'primary' != $args->theme_location ) {
return $items;
}
// Straight concatenation here. Could prepend, or do a regex replace to
// insert the menu item elsewhere
$items .= '<li class="menu-item right">' . date_i18n( get_option( 'date_format' ) ) . '</li>';
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment