Use get_posts with posts_per_page => 1 to get only one latest result. You can than use get_permalink() to get the permalink.
$args = array(
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'DESC',
) ;
$latest_posts = get_posts($args);
$permalink = get_permalink($latest_posts[0]->ID);
Related Posts:
- start_lvl Ignored in Custom walker_nav_menu
- Hide main div if wp_nav_menu is empty
- Menu Items Disappearing
- wp_delete_auto_drafts() deletes links in menus
- Check if a menu is empty?
- how to get permalink structure with php
- Walker class: Problems with understanding how walk() method can be called without error
- How to Use the Function is_user_logged_in To Display Different Menus?
- How to create different menu’s for not logged in visitors and for logged in members?
- How can I access the “description” of a menu item?
- How to place login logout link on menu that redirects users back to current page?
- wordpress upgrade has broken my permalinks
- How can I add a custom class to only nav sub-menu > li > a items in WordPress?
- items_wrap not working
- Style wp_page_menu() items
- wp nav menu: add attributes to menu items [duplicate]
- Have CSS Class Added with `is_page()` WP function
- Run a filter when a walker runs
- Change Navigation Bar based on logged in or not
- Input type search in Menu
- Add prefix to link url
- Change list item content in menu navigation to add a child element with specific class
- How can I Add a variable PHP in the Menu Nav
- Where to place PHP code that inserts (or doesn’t insert) menu item?
- 200 Rewrite blog post links
- Adding an Avatar to the Top Nav Bar
- php script to change slug in post automatically
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- How to use $_GET function WordPress backend
- Unique icons next to each WordPress menu item
- Child page menu in sidebar
- Title Case WordPress Menu Items
- Trying to store submenu items to render out after main menu
- Show About and Contact Us page when they’re clicked in the top menu.
- New walker for walker_nav_menu to change inside container data
- Add data-id attribute to child page links
- Add login hyperlink to secondary navigation menu
- Divi change project category slug
- wp_nav_menu not working correctly in my underscores theme
- Custom post type permalinks do not appear using the link functions
- How to Handle Going Backwards in Navigation When Referrer in PHP/JavaScript won’t work?
- Notice: Trying to get property of non-object
- How to use wp_nav_menu to create custom dropdown menu?
- Get css class of menu item in custom menu structure
- how to edit a specific post slug using a php code?
- Nav-Menu not showing up
- Creating a Category Taxonomy
- WordPress theme showing blank page
- Show login greeting above sub-menu links?
- How to tell if a user has gone in and created a menu
- Hard-coding a shortcode as the last menu item in primary navigation?
- Can not call .php files after switching to %postname%
- Add class to ul and li in wp_na
- Nav Walker that shows only children and siblings of top level parent menu item
- how to changes mobile menu toggle breakpoint in WordPress
- How to display already created menus via php?
- understand what code is doing when prepending /blog
- Providin exception to WordPress wp_nav_menu Custom CSS Classes
- Allow two posts (from different categories) to have the same slug
- Test the existence of a page/article by its URL, taking in consideration the URL rewriting by filters
- Adding markup to sub menu based on class
- Custom PHP form needs refresh to load page correctly
- Child-Theme Category View with modified permalinks (%category% removed)
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- Get WordPress username to customize url
- Menu not updating for logged in users after redirect
- Permalink changes after several minutes after saving post
- How to let mobile navigation menu close when link is clicked?
- Add element after navigation element title don’t works like I expect
- Permalink like example.com/taxonomy/post_type/postname
- How to create a sub-page of sub-page?
- Widget Logic – display on page and all child
- How to list categories by page id in wordpress
- Adding button to wordpress menu
- redirect 301 with special character like WIX site “#!”
- wp_nav_menu doesn’t work in a duplicate server
- How I can add div to menu?
- Weird slug in archives permalink
- Add extra markup to WP menus
- Using ‘array’ method in wp_nav_menu causes it to disappear
- Multiple URL from Custom post name
- How to get the count for each taxonomy term
- WP_Nav Highlight Parent Issue
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Change order that the menu is generated with wp_list_pages
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- How do I modify the with wp_nav_menu()
- PHP code for link with text
- Remove /category/ from category (archive) page URLs (without using a plugin)
- Accessing WordPress Functions get_permalink() in Vanilla PHP?
- Inserting a shortcode into a genesis menu?
- WordPress add parameters with friendly url structure
- Custom nav with bootstrap dropdown
- WordPress CPT & Custom Taxonomy with the SAME Permalink Structure
- Remove slug of multiple custom post types with and without hierarchical
- Can’t assign menu parent id or menu item breaks
- Post returns 404 after changing the permalink using post_type_link
- prevent category page from also highlighting blog-page menu