Using WordPress ‘form_option()’ PHP function

The form_option() WordPress PHP function prints an option value after sanitizing it for forms.

Usage

Here’s a basic usage of form_option():

form_option('blogname');

In this example, the function is retrieving the value of the option ‘blogname’ (which is the title of your WordPress site), sanitizing it, and printing it.

Parameters

  • $option (string): The name of the option you want to retrieve and print. This is required.

More Information

See WordPress Developer Resources: form_option()

This function has been in use since WordPress version 2.1. As of the current version, it has not been deprecated. The source code for this function can be found in wp-admin/includes/template.php.

Related functions include get_option(), update_option(), and delete_option().

Examples

Displaying Blog Name

This example retrieves and prints the title of your WordPress site.

form_option('blogname');

Displaying Site URL

This example retrieves and prints the URL of your WordPress site.

form_option('siteurl');

Displaying Admin Email

This example retrieves and prints the admin email of your WordPress site.

form_option('admin_email');

Displaying Default Category

This example retrieves and prints the default category of your WordPress site.

form_option('default_category');

Displaying Date Format

This example retrieves and prints the date format of your WordPress site.

form_option('date_format');

Remember that the output of form_option() is automatically sanitized, making it safe for use in forms. It’s a handy function for quickly retrieving and displaying option values.