Headless mode allows you to use software without an interface. In TSF v4.1.4, we introduced this turnkey feature. It works well with TSF because it can automatically generate metadata.
To enable it, you have to define constant THE_SEO_FRAMEWORK_HEADLESS
in either a (mu-)plugin or the wp-config.php
file. It must be defined before WordPress’s Core action plugins_loaded
, priority 5
.
Different modes
The constant THE_SEO_FRAMEWORK_HEADLESS
accepts only true
or an array of selectively disabling values. Any other data entered will enable headless mode altogether.
Full headless mode
All interfaces disappear using this mode.
define( 'THE_SEO_FRAMEWORK_HEADLESS', true );
Partial headless mode
In the following example snippet, neither user-meta nor post/term-meta are headless. The settings-interface is headless and hidden thus (headless equals true
).
define( 'THE_SEO_FRAMEWORK_HEADLESS', [ 'user' => false, 'meta' => false, 'settings' => true ] );
If you do not define an index, such as in the example below, they’ll default to true
(headless). In the example below, everything but the post/term-meta interface is headless.
define( 'THE_SEO_FRAMEWORK_HEADLESS', [ 'meta' => false ] );
Conditional headless mode
A few users asked us how to hide TSF’s interface from Authors and Editors, but they still wanted to be able to edit the SEO metadata as Administrators — that metadata must then be used on the front-end. To achieve this, we need to check if we’re in the admin area and then if the current user has administrator privileges. Only via a (mu-)plugin, you can do this before The SEO Framework loads.
In this example, we enable headless mode in the admin area for anyone except super admins (i.e., a user who can delete_users
on single sites or is assigned the super admin-role on WordPress Multisite networks). This way, the metadata can still be loaded on the front-end.
add_action(
'plugins_loaded',
function () {
if ( is_admin() && ! is_super_admin() )
defined( 'THE_SEO_FRAMEWORK_HEADLESS' )
or define( 'THE_SEO_FRAMEWORK_HEADLESS', true );
},
0,
);
We also made a snippet-plugin of this code. Download it here. Learn how to install a snippet-plugin.
Data defaults
With headless mode enabled on the front-end, all options and post/term/user meta-data use default values, and won’t try accessing values from the database. You can overwrite these defaults via filters, aptly named:
the_seo_framework_post_meta_defaults
the_seo_framework_term_meta_defaults
the_seo_framework_user_meta_defaults
the_seo_framework_default_site_options
Please note that when you enable headless-mode in the admin area only, the filters above might not run: stored data can be used instead. To overwrite stored data, use the following aptly-named filters:
the_seo_framework_post_meta
the_seo_framework_term_meta
the_seo_framework_user_meta
the_seo_framework_get_options
Extension Manager support
When you enable headless mode for settings ('settings' => true
), Extension Manager‘s interface becomes inaccessible; however, you can implement various constants to control Extension Manager. Primarily, you’d want to use TSF_EXTENSION_MANAGER_API_INFORMATION
and TSF_EXTENSION_MANAGER_FORCED_EXTENSIONS
. Extensions that do not work well with headless mode are Cord, Local, and Monitor.