WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 10 months ago

#19902 new feature request

blog_url() and get_blog_url() template tags

Reported by: johnjamesjacoby Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.3.1
Component: Permalinks Keywords: has-patch 2nd-opinion
Focuses: Cc:

Description (last modified by johnjamesjacoby)

With usage of WordPress as a CMS increasing, the blog is not always the focal point. It would be great if there were template tags available to get the blog url, basically a wrapper for getting the options if it's set to a WordPress page, and defaulting to home_url( '/' ) if not.

Patched against r19759 (trunk)

Attachments (1)

19902.diff (1.5 KB) - added by johnjamesjacoby 3 years ago.

Download all attachments as: .zip

Change History (13)

@johnjamesjacoby3 years ago

comment:1 follow-ups: @nacin3 years ago

Since we already have site_url(), let's try to pick a name that is less confusing. Perhaps blog_page_url() or something.

This might be a duplicate of another ticket, but I'm not locating anything.

comment:2 in reply to: ↑ 1 ; follow-up: @johnjamesjacoby3 years ago

Replying to nacin:

Since we already have site_url(), let's try to pick a name that is less confusing. Perhaps blog_page_url() or something.

Agree the nomenclature gets increasingly confusing. Possible permutations:

  • get_/blog_url()
  • get_/blog_link()
  • get_/blog_permalink()
  • get_/blog_page_url()
  • get_/blog_page_link()
  • get_/blog_page_permalink()
Last edited 3 years ago by johnjamesjacoby (previous) (diff)

comment:3 @johnjamesjacoby3 years ago

  • Description modified (diff)

comment:4 @evansolomon3 years ago

I wrote a similar patch before finding this ticket, which covers pretty much everything I thought of. An additional idea I had was to return the last post if the blog uses a static front page but doesn't have a posts page set. In that case, I think the last post (if one exists) makes the most sense as their blog URL.

comment:5 in reply to: ↑ 1 @ericlewis23 months ago

This is sorely needed.

Replying to nacin:

Since we already have site_url(), let's try to pick a name that is less confusing. Perhaps blog_page_url() or something.

I'm good with get_blog_url(), it fits well with the other link template tags we already have.

comment:6 @SergeyBiryukov22 months ago

#25423 was marked as a duplicate.

comment:7 @SergeyBiryukov22 months ago

Found a use case for get_blog_url() in wp_list_categories():
tags/3.6.1/wp-includes/category-template.php#L460.

comment:8 in reply to: ↑ 2 @ericlewis22 months ago

Replying to johnjamesjacoby:

Agree the nomenclature gets increasingly confusing.

get_blog_index_url() and blog_index_url() is another naming option that read less confusing to me than get_blog_page_url() and blog_page_url(), and more specific than blog_url() and get_blog_url()

comment:9 @nacin17 months ago

  • Component changed from Template to Permalinks

comment:10 @johnjamesjacoby10 months ago

I can get with get_blog_index_url() and blog_index_url(), and I still believe these helper functions would be highly useful to plugin developers and on multisite/network installs.

comment:11 follow-up: @SergeyBiryukov10 months ago

It would be great if there were template tags available to get the blog url, basically a wrapper for getting the options if it's set to a WordPress page, and defaulting to home_url( '/' ) if not.

This sounds similar to how is_front_page() works, so I'd suggest get_front_page_url() and front_page_url() for consistency.

comment:12 in reply to: ↑ 11 @johnjamesjacoby10 months ago

Replying to SergeyBiryukov:

This sounds similar to how is_front_page() works, so I'd suggest get_front_page_url() and front_page_url() for consistency.

is_front_page() and is_home() are only two poorly-named parts of the equation.

  • Getting the front-page URL is easy; it's always the root of the site domain + path. This can be done quite easily virtually anywhere (wp_options, wp_blogs, wp_site, wp_bp_blogs for buddypress.) We have helper functions to tell us whether or not there are posts at this root location, but no function to return the URL if they are not.
  • Getting the blog-index URL is less-easy, requiring something akin to the attached patch. Once the post index is changed from the root/front/home, it could reside almost anywhere. The attached patch attempts to shed light on where that might be, from outside the context of the current blog/site/network.
Note: See TracTickets for help on using tickets.