25
votes

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

How can I get blog page url?

6

6 Answers

58
votes

You can use get_option of page_for_posts to get the page ID to either assign it to a variable or to echo it.

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

For more information of the default get_option visit: Option Reference

10
votes

We can use get_post_type_archive_link since WordPress 4.5

get_post_type_archive_link( 'post' );
2
votes

$posts_page_url is the url to blog page and $posts_page_title is the page title

<?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  );
?>

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

2
votes

Just call your url with this extention and all blog posts are displayed.

https://www.yourdomain.com/?post_type=post

2
votes

If your blog url is https://www.yourdomain.com/blog, you can use:

echo site_url('/blog');
1
votes

use this code:

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