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.

Syntax


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.

Examples

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

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Give buttons accessible namesUI/UXSELF JOIN in PostgresPostgresHow destructuring works in React?ReactSome EASY-to-Understand CSS media query examplesCSSDynamically generate names in SCSS (animation example)SCSSUse eq() method in jQueryjQuery