Get the URL of a blog page in WordPress

The blog page on my WordPress website is set to a page other than the main page. I want to get a link to this blog page from any other pages.

How can I get the url of a blog page?

+15
source share
5 answers

You can use get_option for page_for_posts to get the page id, to assign it to a variable, or display it.

 <?php echo get_permalink( get_option( 'page_for_posts' ) ); ?> 

For more information about the default visit, get_option : Option Reference

+32
source
 <?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>"> 
+2
source

$ posts_page_url is the URL of the blog page, and $ posts_page_title is the name of the page

 <?php $posts_page_id = get_option( 'page_for_posts'); $posts_page = get_page( $posts_page_id); $posts_page_title = $posts_page->post_title; $posts_page_url = get_page_uri($posts_page_id ); ?> 

For more details see the link - http://www.queness.com/code-snippet/7935/how-to-get-url-for-blog-page-when-using-static-homepage

+1
source

use this code:

 <?php echo '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">Our Blog</a>'; ?> 
+1
source

We can use get_post_type_archive_link since WordPress 4.5

 get_post_type_archive_link( 'post' ); 
0
source

Source: https://habr.com/ru/post/1258375/


All Articles