Advertisement

Get WordPress Blog URL from Anywhere

Quite a few times when building a WordPress theme, mostly those being built for clients, it’s handy being able to get the URL of the blog dynamically, so no matter what changes in the future, that link will always work. Here’s how you can do exactly that with get_option():

// Get the blog page ID
$blog_id = get_option('page_for_posts');

// Get the blog page URL
get_permalink($blog_id);
<!-- HTML link version -->
<a href="<?php echo get_permalink(get_option('page_for_posts')); ?>">Blog</a>

Advertisement

Web designer and developer from Southampton, UK.


Comments are closed for this post.

Advertisement

Inspirational Newsletter

Join the newsletter to get the best articles, tutorials and exclusive freebies every two weeks.

No spam. You can unsubscribe at any time.