How to get blog URL in WordPress

In : 


Last Updated : 04/04/2018

Use the "get_option( 'page_for_posts' )" Wordpress function to get blog url of the static page.

How to get blog URL in WordPress

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.

WordPress get blog URL code

$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.

Here are some articles that you should read next
Authored By Kinjal Desai
Kinjal Desai - Co-Founder & Blogger

Got Something To Say

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>