Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( ! is_admin() ) {
- // Hook in early to modify the menu
- // This is before the CSS classes are calculated
- add_filter( 'wp_get_nav_menu_items', 'replace_placeholder_nav_menu_item_with_latest_post', 10, 3 );
- }
- // Wee long function names! :P
- function replace_placeholder_nav_menu_item_with_latest_post( $items, $menu, $args ) {
- foreach ( $items as $item ) {
- // Find the placeholder
- if ( '#latestpost' != $item->url )
- continue;
- $latestpost = get_posts( array(
- 'numberposts' => 1,
- ) );
- if ( empty( $latestpost ) )
- continue;
- $item->url = get_permalink( $latestpost[0]->ID );
- }
- return $items;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement