Last Updated: February 25, 2016
·
1.642K
· gilbitron

WordPress get_blog_url()

Have you ever needed to find the WordPress blog URL? Using home_url() is fine but what if your Settings > Reading options in WordPress are set to your blog having a static page (usually called “Blog”). You may need to know what the URL of that page is. So here is a quick function I came up with to find it.

if ( !function_exists( 'get_blog_url' ) ) {
    function get_blog_url(){
        if( $posts_page_id = get_option('page_for_posts') ){
            return home_url(get_page_uri($posts_page_id));
        } else {
            return home_url();
        }
    }
}

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
#wordpress
Did you know?

WordPress sites collect scripts from themes, plugins, and tag managers. A compromised plugin update can add a skimmer to every page without a change in your own templates.

Security insights from Cside