As an example, let's say I set my "About Us" page (slug: about-us) as my home page static page. Upon doing this, when someone requests mysite.com/about-us, WordPress does a nice redirect to the home page so that I don't end up with duplicate content of having two pages pointing to the same content.

I'm trying to find where in the core code that this redirect code appears, because I'm trying to emulate the same behavior when using a sticky post as the home page.

  • Just out of curiosity: Did you have to go the page-template way, or did setting page_on_front to the sticky post's ID suffice? – Johannes Pille Jun 2 '12 at 7:59

First off, the behavior you describe is not a redirect but a URL rewrite.

That being said, there's a WordPress option called page_on_front that is set to the page ID of the static page to be used as a front page. This option's value is only relevant if the option show_on_front is set to page (that happens if you set "Front page displays" to "A static page" in the "Reading" panel).

enter image description here

Depending on the page you select from the dropdown below that radio box, page_on_front is set.

You can however also set options programmatically. The following approach is untested and just a quick idea off the top of my head, but it should be possible to simply set this option to the sticky post's ID and be done with it:

$sticky_id = // set to post ID you want to display
update_option( 'page_on_front', $sticky_id );

Another approach (if this first idea fails) might be to set the front page to a regular static page, assign that page a custom template, leave the page content empty and incorporate a custom loop that grabs the latest sticky post in said page template. That ought to work fo'shizzle.


I believe this page will have the best information for you: http://codex.wordpress.org/Class_Reference/WP_Rewrite


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.