Yogesh Chauhan's Blog

How to get front page or home page ID in WordPress?

in WordPress on July 6, 2021

Solution Code

If you’re in a rush, here’s a one line solution:

$homepage_id = get_option('page_on_front');

get_option function

WordPress has many functions that can be used (or just a wordaround) to get the homepage ID.

One of those many functions is get_option.

get_option gives you an option value based on the option name you pass.

Few things to remember

  • If the option doesn’t exist then it will return false.
  • If the option doesn’t have any value, it will return false too.
  • It will return unserialized value even if the option value is serialized.


get_option($option, $return_value)

Where $option is a string and a required parameter. $return_value is not required so if you don’t pass it, it will take the default value as false. You can ask for array, boolean, float, integer, null, object, and string as a return value.


Get blog/site name

echo get_option( 'blogname' );

Get blog/site description

echo get_option( 'blogdescription' );

Get admin email

echo get_option( 'admin_email' );

Get date format from settings

echo get_option( 'date_format' );

Get time format from settings

echo get_option( 'time_format' );

Checkout WP Docs for more

get_option function on WordPress

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Killing A Project Part 2: Who should make the decision to kill a project?MiscellaneousThe simple difference between var, let and const in JavascriptJavaScriptLearn to Implement Estimated Reading Time using PHP Part 1: The BasicsPHPWhat’s the difference between variables in CSS and SCSS (Sass)?CSSHow to calculate elapsed time in JavaScript?JavaScriptConditional operator in JavaScript (aka ternary operator)JavaScript