Make WordPress Core

Opened 13 years ago

Closed 10 years ago

#18705 closed enhancement (maybelater)

home_url() and is_home() with a static front page

Reported by: crrobi01's profile crrobi01 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

When you have a static front page, home_url() points to the front page while is_home() detects the posts page.

This is confusing and counter intuitive (especially because in the dashboard the page set as home is referred to as the posts page. The word "Home" is never used on the client side).

Rename
is_home() => is_posts_page()
home_url() => front_page_url()

Add
posts_page_url()

Change History (11)

#1 follow-up: @johnbillion
13 years ago

  • Type changed from defect (bug) to enhancement

+1 for renaming is_home() to is_posts_page() (this hass been brought up before).

I don't think the name of home_url() needs to change. If we deprecate is_home() then 'home' won't have its confusing meaning any more.

The introduction of posts_page_url() and front_page_url() is a good idea.

#2 in reply to: ↑ 1 ; follow-up: @alex-ye
12 years ago

Replying to johnbillion:

+1 for renaming is_home() to is_posts_page() (this hass been brought up before).

I don't think the name of home_url() needs to change. If we deprecate is_home() then 'home' won't have its confusing meaning any more.

The introduction of posts_page_url() and front_page_url() is a good idea.

1+ for posts_page_url() , but I don't think we need front_page_url() it's the same as home_url() ?

#3 in reply to: ↑ 2 @johnbillion
12 years ago

Replying to alex-ye:

1+ for posts_page_url() , but I don't think we need front_page_url() it's the same as home_url() ?

I'm not bothered either way. The idea is to remove the inconsistency between is_home(), which is true for the posts page, and home_url(), which gives you the front page URL. It should be sufficient to deprecate is_home() in favour of is_posts_page().

#4 @crrobi01
12 years ago

Suppose you deprecate is_home() in favor of is_posts_page() and add posts_page_url(). Now we have:

is_front_page()
is_posts_page()
home_url();
posts_page_url()

I'm suggesting we rename home_url() to front_page_url() because home_url() doesn't point to the page that loads home.php when you have a static front page. It points to front-page.php

Alternatively we could do:
is_front_page()
is_home()
front_page_url()
home_url()

Which is more consistent because the posts page template is called home.php
To do this create a function called front_page_url() which works how home_url() currently works and change the function of home_url() to how our proposed function posts_page_url() would work.

#5 @crrobi01
12 years ago

  • Type changed from enhancement to defect (bug)

I changed type back to defect. Under certain conditions, home_url() does not point to the page which loads the template home.php. This is a bug.

The only enhancement here is to create the function front_page_url() because after home_url() is fixed, you lose that functionality. That's not an enhancement, its the preservation of a current feature and the fixing of another.

EDIT: It's worth nothing that when is_front_page() and is_home() are both true,
front-page.php is loaded instead of home.php. I think this is also a mistake. Suppose a theme has front-page.php for a special banner image template (which doesn't include The Loop) and home.php for the blog. Now the user can never have their blog on the front page. If we load home.php in favor over front-page.php then the user gets all the functionality as before, but also the ability to have their posts page on front if they so choose. No reason not to do this.

The template hierarchy issue might be worthy of a new ticket, but the front/home dynamic is so confused that I'm just going to leave everything here.

Last edited 12 years ago by crrobi01 (previous) (diff)

#6 @nacin
12 years ago

  • Type changed from defect (bug) to enhancement

The home in home_url() and is_home() are different concepts. This is confusing, but it isn't a bug.

#8 @grantnorwood
12 years ago

+1 for updating the language of is_home() to better reflect the blog index page, but it seems to me that a function called is_posts_page() would make more sense if it returned true when the current page were *any* of the blog-related pages (archive, author, cat/tag, date, etc), not just the index page.

Better names for the blog index page (currently is_home()) might be is_blog_home(), or is_posts_home(), which makes it more clear that it is the "home" page for the blog posts.

Also, that would allow a new is_blog_page() function to be created to conditionally check if *any* of the post-related pages are currently being viewed, which is handy when you want to apply templates/styles to more than just the is_home() page.

Please see my ticket #21620 for adding a new function which checks for any of the blog-related pages, regardless of the naming or implementation of the existing is_home() function. I've already attached a patch that I hope is helpful to all.

#9 @chipbennett
11 years ago

  • Cc chip@… added

#10 @pauldewouters
10 years ago

  • Cc pauldewouters@… added

#11 @nacin
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.