YM Fast Options is a powerful tool for customizing your WordPress site’s settings. Below are instructions on how to install and configure it.
Getting Started
Installing the Plugin
Begin by installing the YM Fast Options plugin. You can do this through the WordPress admin panel or by uploading the plugin files.
Next, access your theme’s functions.php
file. It can be found at the following path:
../wp-content/themes/your-theme/functions.php
Then check if the plugin is activated by using the following code snippet in the functions.php
file:
// Registers YMFO custom options. if ( class_exists( 'YMFO' ) ) { // Next code here... }
Creating options page
To create an options page, you can use the following code snippet. In this example, we will create a Contacts page:
$contacts_page = new YMFO_Page( 'Contacts', 'contacts' );
The first function argument is the page title, and the second is the page slug.
Adding section
Now, let’s create a section for social media links within the Contacts page:
$contacts_page->add_section( 'Social Media', 'social_media' );
The first function argument is the section title, and the second is the section slug.
Adding fields
Next, we will add fields for various social media links to the Social media section:
$contacts_page->add_field( 'YouTube', 'youtube_link', 'url', 'social_media' ); $contacts_page->add_field( 'Facebook', 'facebook_link', 'url', 'social_media' );
The first function argument is the field title, the second is the field slug, the third is the field type (you can find allowed types below) and the fourth is the field section slug.
That’s it!
You can now find your new options page in the WordPress admin sidebar.
The final code is:
// Registers YMFO custom options. if ( class_exists( 'YMFO' ) ) { // Registers settings page. $contacts_page = new YMFO_Page( 'Contacts', 'contacts' ); // Adds settings section. $contacts_page->add_section( 'Social media', 'social_media' ); // Registers options and adds fields. $contacts_page->add_field( 'YouTube', 'youtube_link', 'url', 'social_media' ); $contacts_page->add_field( 'Facebook', 'facebook_link', 'url', 'social_media' ); }
Getting options values
To get your options values use ymfo_get_option( $page_slug, $field_slug )
function or ymfo page="$page_slug" option="$field_slug"
shortcode.
For example, let’s print a link to YouTube channel:
<a href="<?php echo esc_attr( ymfo_get_option( 'contacts', 'youtube_link' ) ); ?>">YouTube</a>
Allowed Field Types
- text
- textarea
- number
- select
- checkbox
- radio
- tel
- url
- image
- date
- datetime-local
- month
- week
- time
- color
Examples
Page with subpages
To create a page with subpages you can use callback
and parent_page
arguments.
For top page you need to set page slug the same as the first subpage’s slug and callback
argument as null
, to disable page print callback.
For subpages you need to set $top_page
variable as the parent_page
argument.
// Registers YMFO custom options. if ( class_exists( 'YMFO_Page' ) ) { // Registers top-level page. $top_page = new YMFO_Page( 'My Company', 'contacts', [ 'callback' => null, ]); // Registers first subpage. $contacts = new YMFO_Page( 'Contacts', 'contacts', [ 'parent_page' => $top_page, ]); // Registers second subpage. $settings = new YMFO_Page( 'Settings', 'settings', [ 'parent_page' => $top_page, ]); }
Multisite network options
To create a settings page for a sites network, you must set the in_network
argument to true
.
If you add subpages, they will automatically have the same in_network
value as the parent, even if you set them to a different value.
// Registers YMFO custom options. if ( class_exists( 'YMFO_Page' ) ) { // Registers network page. $network_page = new YMFO_Page( 'My Company', 'contacts', [ 'in_network' => true, ]); // Registers contacts page. $contacts = new YMFO_Page( 'Contacts', 'contacts', [ 'parent_page' => $network_page, 'in_network' => false, // Will be ignored. ]); }