May 20, 2016
Get Blog Posts Page URL (Permalink) in WordPress
To get the URL (permalink) to the main blog posts page, you can use the function below. It will return the blog posts page URL whether the front page or another static page is set as the blog posts page.
/**
* Get blog posts page URL.
*
* @return string The blog posts page URL.
*/
function km_get_blog_posts_page_url() {
// If front page is set to display a static page, get the URL of the posts page.
if ( 'page' === get_option( 'show_on_front' ) ) {
return get_permalink( get_option( 'page_for_posts' ) );
}
// The front page IS the posts page. Get its URL.
return get_home_url();
}