1

According to the WP_Class reference, $post->post_name holds the value of the slug of the current page being viewed. If I'm currently viewing the WP admin edit screen for my homepage as set under Settings > Reading > Front page displays > A static page > Front page, what would be the value of $post->post_name if I do the following?

global $post;
echo $post->post_name;

I wasn't aware my homepage had a slug. Would the value be an empty string? Hoping someone can help clarify. Thanks in advance.

4
  • 1
    I believe that reference to the $post object only applies on the front end.
    – vancoder
    Commented Jun 27, 2014 at 21:45
  • I think it applies to the edit screen as well. Commented Jun 27, 2014 at 21:46
  • @vancoder on 2nd thoughts, I think you might be right Commented Jun 27, 2014 at 21:57
  • @vancoder on 3rd thoughts, I think it does actually apply to the edit screen as well. Commented Jun 28, 2014 at 1:48

1 Answer 1

1

post_name would be the slug as it was set before the page became the front page. When the URL for the front page is output via the API, the get_page_link function checks if the ID matches the page_on_front option and returns the home_url in that case. This is why you should always use the API to output data and not directly access post object fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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