You can use the wp_get_recent_posts function in your own custom function.
Something like this should work:
function get_recent_post_link(){
// Restrict to latest post
$args = array( 'numberposts' => '1' );
// Get the post
$latest_post = wp_get_recent_posts( $args );
foreach( $latest_post as $the_post ){
return get_permalink($the_post["ID"]);
}
}
You can the call the function in your anchor:
<a href="https://wordpress.stackexchange.com/questions/257142/<?php echo get_recent_post_link(); ?>">Latest</a>
Note, I have not tested this, please use as a guideline.
Related Posts:
- Add custom menu item using wp_nav_menu_items filter
- Removing link ” from ” menu for some “links” without JS
- Using filters to change href of nav menu page link
- Links open only on new tab or window
- How to get current page menu item name instead of full menu item list
- Adding different classes to anchor in navigation menu
- Pending Custom Link in Menu
- Force PDF download from custom menu?
- Page-Linking Structure
- How to add wechat (weixin) link to navigation menu?
- Admin only menu/page
- Image as a link using wp_nav_menu()
- Fragment URL in navigation item without a custom link
- Link to Homepage in Menu
- Separator for custom nav menu
- How do you link to a place in another page without any styling issues?
- Custom Links menu items include in Search Results
- Menu custom link not working for external site
- Why is wordpress forcing https link generation?
- Links do not open from click, only in new tab [closed]
- Adding existing links to custom navigation menus?
- How to change the link on the logo at the menu?
- Creating Menu Links in a Custom Theme
- The cart, checkout, and shop links not getting removed
- URL links consistent with menus?
- Opening Menu link in another tab
- Active class to current link
- How to add class to anchor using wp_nav_menu
- Simple form to add custom links to menu?
- Main menu navigation links and new pages
- custom menu widget where menu title is a link
- 2 item in a same menu pointing to 1 page
- How to show pages in menu without link
- Problem with links once in portfolio item
- How to create a link-less parent (top level) menu item that doesn’t use an anchor tag
- Menu links URL with PHP GET method
- Classes CSS (Optional) – how do I reference this in php?
- Why does WordPress convert absolute URLs to relative URLs for menu items?
- Parent link need to go first child submenu
- Add a data attribute to list item element in menu
- Links in new menu don’t work
- How to make menu output links absolute
- change link of menu particular tab
- Menu Structure with Links failure to update
- Top menu link anchor href value change after online server?
- Show content of subdomain from specific menu-item?
- Navigational error
- How do I add a link to the menu that has a charector (?) in it?
- Remove link from Page name in navigation bar
- Change menu item order
- Menu System: Custom Links
- Unsual behaviour of navigation Menus
- How to centre menu items on horizontal nav bar? (e.g. make margins equal) [closed]
- Wrapping my ‘s with
- Displaying list of random links using wp_nav_menu
- WordPress removes URL parameters from menu elements when saving the menu
- how to add permalink/slug to wordpress custom link menu item
- Main Menu Hover is Always White
- How to avoid wp_nav_menu() ID conflict?
- Creating new dynamic menu including BP links [closed]
- Hide menu items for visitors and filter based on role
- Add a “has-children” class to body tag?
- Custom Nav Walker sub-menu HTML construct
- How to remove trailing tags from wp_nav_menu walker
- How to scroll item in the Menu setting effectively?
- Building custom API and using wp_get_nav_menu_items to get menu items. Only works when logged in, returns nothing when I’m not
- Appearance -> Menu -> Menu Structure : Add plain HTML code as an element
- wp_nav_menu add some element to container
- Custom menu deletes itself
- show different admin menu to different user roles
- How to include a third level with wp_get_nav_menu_items function
- How do you manage large menu hierarchies in WP?
- how can remove this element to avoid having two menu buttons with one that shows unnecessary pages
- WordPress Menu Walker: add #hashes to child page links (only)
- Custom Menu’s – Disable Link checkbox
- How to remove menu labels in word press?
- Adding numbers inside a span tag in nav menu [closed]
- I’m using wp_nav_menu to display my menu, but I want one more link in there that is a hardcoded link. How can I do this?
- Disable parent in wp_list_pages – WordPress
- Add scheduled page or post in the menu section on back-end
- Hoverable menu to appear in different sections of page
- Show Sidebar Menu Subpages When Clicking Parent
- Current User In Custom Menu Item URL [closed]
- Creating other page than page.php
- Dynamically populate the menu when a new category is created
- Menu items not clickable
- How do you show horizontally the submenu in WordPress using the nav walker?
- Add “onclick” option to header menu item
- Mobile menu not working – jQuery error?
- Responsive Dropdown Menu
- How to separate sub-menu output and keep associated with parent
- Eliminate menu collapse button on website
- Best way to build a 500 item menu
- Count Level 1 Childs for Custom Nav Walker WordPress
- Showing main menu and child menu in diffent places in a same page
- Display same menu for parent and all its children
- Permalinks linking to similar named site
- Custom navigation / menu output (walker?)
- How does WP knows which template to use for a page
- Database structure Menu Item