Use the "get_option( 'page_for_posts' )" Wordpress function to get blog url of the static page.
By default, WordPress themes display all blog posts through “index.php” file order by most recent posts. But many WordPress developers want to use static pages for Homepage and Posts page. Sometimes, The blog page (post page) needs to be linked to the homepage and others. WordPress allows you to get a blog page (post page) ID using the pre-built function. Using blog page id, you can fetch all data from the page.
Use the “get_option()” WordPress function and “page_for_posts” option parameter. The “get_option()” function return ID of the blog posts page. Here I added an example of how to get URL for blog page when using static posts page. Put this code in your theme’s “*.php” file, where you want to show the link of latest posts page.
<?php $posts_page_id = get_option( 'page_for_posts' ); $posts_page = get_post( $posts_page_id ); $posts_page_title = $posts_page->post_title; $posts_page_guid = $posts_page->guid; ?>
Write anchor tag and put fetched title and permalink in its attributes.
<a href="<?php echo $posts_page_guid; ?>" title="<?php echo $posts_page_title; ?>"><?php echo $posts_page_title; ?></a>
If you have any query regarding “WordPress get blog URL“, Let me know in a comment section. I will try to solve your query.