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:
- Adding first / last CSS classes to menus
- Hide main div if wp_nav_menu is empty
- how to put the logo in the center of other items in the navigation bar
- Facebook Comment Count
- How to remove a metabox from menu editor page?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- How to create different menu’s for not logged in visitors and for logged in members?
- Can we have a php “page” without a WordPress “page”?
- How to add active class to custom menu using while loop and wp_list_pages
- How to place login logout link on menu that redirects users back to current page?
- wp_delete_auto_drafts() deletes links in menus
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- Logout and redirect using the WP Menu
- Creating new menu item
- Programmatically create menu with custom link
- Custom Loop through category menu to include sub categories
- Featured image fallback link to permalink
- wp nav menu: add attributes to menu items [duplicate]
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Change Navigation Bar based on logged in or not
- create a select input with menus created on a custom options page
- How can I Add a variable PHP in the Menu Nav
- Where to place PHP code that inserts (or doesn’t insert) menu item?
- Adding an Avatar to the Top Nav Bar
- Add data attribute to each li in menu
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Remove metabox from WordPress menu editor page?
- WordPress Persistent connection rule does not work for “posts”
- How to add an arrow to menu items has submenus
- wp_nav_menu returns menu list in ascending order. How can I arrange the menu same as dashboard menu
- Unique icons next to each WordPress menu item
- Secondary navigation menu on one page
- Remove class in nav_menu_link_attibutes filter
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Create custom permalinks to show Custom Post Type’s relationship?
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- Adding PHP in the menu
- get_template_directory_uri() providing wrong path for img
- 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
- wp_nav_menu not working correctly in my underscores theme
- Notice: Trying to get property of non-object
- How to use wp_nav_menu to create custom dropdown menu?
- Adding Additional Variables on Menus Page
- how to edit a specific post slug using a php code?
- Nav-Menu not showing up
- WordPress theme showing blank page
- How to tell if a user has gone in and created a menu
- Strip hashtag off permalink with php
- Class for Selected Menu using wp_nav_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?
- 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
- Featured image in menu wordpres
- 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
- Rewrite rule not working, but only when parameter is text
- Get WordPress username to customize url
- Post permalink buttons all going to the first post
- How to let mobile navigation menu close when link is clicked?
- WordPress/NGINX not respecting the category URL for new posts
- PHP warning with code for nav menu walker [duplicate]
- Add element after navigation element title don’t works like I expect
- Permalink like example.com/taxonomy/post_type/postname
- String replace for Login/Logout concatenation problem in menu
- 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?
- wp_nav_menu prints children with parent name
- Weird slug in archives permalink
- WP Admin Bar – Get current theme name as custom menu title
- Using ‘array’ method in wp_nav_menu causes it to disappear
- Newly published content gives 404 on wordpress
- Multiple URL from Custom post name
- How to get the count for each taxonomy term
- WP_Nav Highlight Parent Issue
- get_permalink returning first letter
- Submenu opened problem
- 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?
- 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 Navigation Bar JSON Syntax Error in JSON at Position 0
- how to goto specific page number including title with permalink
- How to extract URLs from wordpress taxonomies
- WordPress 6.1.1 UTF8 Slug Limit Increase