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?
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
We can use get_post_type_archive_link since WordPress 4.5
get_post_type_archive_link( 'post' );
$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
Just call your url with this extention and all blog posts are displayed.
If your blog url is https://www.yourdomain.com/blog, you can use:
echo site_url('/blog');
use this code:
<?php echo '<a href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">Our Blog</a>'; ?>
To get the Blog URL you can use the below code.
get_permalink( get_option( 'page_for_posts' ) );
If you are using WordPress 4.5+ then you can use the below code which will work for any post type.
get_post_type_archive_link( 'post' );