WordPress: Get the ID for the Front Page and Home

Normally in WordPress if you wanted to access an ID for a post or page you would reference the global $post variable. However, what if you wanted to access the ID for the Home and Front Page templates?

In that case you will need to reference the stored ID from the WordPress database using the get_option function.

Using WordPress get_option

This function is used to quickly reference a specific option from the database.

$front_id = get_option('page_on_front');
$blog_id = get_option('page_for_posts');

By accessing these stored IDs you will then be able to use functions like get_the_title() to store the title for example.

$title = get_the_title($blog_id)

You can also use the front page and home ID to access meta information.

$front_meta = get_post_meta($front_id, '_meta_key', true);

Remember these two options, they will save you a tonne of time.

In Category: WordPress

Matthew Horne

I am a web developer from the United kingdom who taught himself PHP and JavaScript and continues to build on those skills as well as learn new skills.

Show 0 Comments
No comments yet. Be the first.

Leave a Comment