How to work with Wordpress blog settings

Wordpress blog settings are stored in the wp_options database table and can be read with the get_option($setting) function. This function applies pre_option_{setting} filters, checks whether the option is already loaded, and returns its value by fetching it from the database or from the cache.

Wordpress has more then 90 options but most frequently used of them are the following (in alphabet order):

 

  • blog_charset
  • blogname
  • date_format
  • default_category
  • default_ping_status
  • gmt_offset
  • home
  • permalink_structure
  • siteurl
  • time_format

There are several functions for managing options: update_option($name, $value), add_option($name, $value, $depricated, autoload), delete_option($name).

Most of the options can be modified in wp-admin. For example, the “Front page displays” option that specifies whether front page should display list of latest posts or specific page can be configured on the “Reading Settings” page in the wp-admin/options-reading.php file. After modifying, this setting is saved by the wp-admin/options.php file in the show_on_front, page_on_front, and page_for_posts options.

With this information we can create a simple function that checks whether the current page is the front page of a Wordpress site:

function is_front_page2() {
  if (’page’ == get_option(’show_on_front’)
    && 0 != ($id = get_option(’page_on_front’))
    && null != ($page = get_page($id)))
    return is_page($page->ID);
  return is_home();
}

is_front_page2 was chosen because the is_front_page function exists, but it returns wrong result when show_on_front = ‘page’ and page_on_front == 0 and page_for_posts != 0.

Tags:

Leave a Reply