dots Created with Sketch.
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 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jul 22 Is there a CSS parent selector? #Jul 22 Difference between :where and :is in CSS #Jul 22 Does :is() pseudo selector hint at CSS preprocessing in the future? #Jul 22 Control Scrolling with CSS Scroll Snap #Jul 21 Control rendering using CSS content-visibility property #Jul 21 How to use @supports rule in CSS?
You might also like these
How to compress images with gulp in WordPress?WordPressWHERE Clause in PostgresPostgresHow to create a simple tab interaction using CSS?CSSHow to show slider value in HTML5 range input using JavaScript?HTMLHow to Recognize an Array in JavaScript?JavaScriptWhat is IPS(Intrusion Prevention System), How Does It Work and What are the Detection Types?Miscellaneous