Browse AjaxPress docs

PHP hooks and filters

On this page

Filters and actions for customising AjaxPress from a theme or plugin. Put them in your theme’s functions.php, or better, in a small site plugin or a code snippet, so they survive a theme change.

ajaxpress_ajax_login

Whether wp-login.php runs with AjaxPress, so logging in and registering there happen without a page reload. Default true.

// Keep wp-login.php as a normal page.
add_filter( 'ajaxpress_ajax_login', '__return_false' );

To send every login and registration form (WooCommerce’s included) through a normal page load, turn on Full Page Reload on Login & Registration in the settings instead.

ajaxpress_keep_block_navigation

On block themes, AjaxPress switches off WordPress’s own client-side navigation scripts (the Interactivity API router and the Query Loop’s navigation), because they compete with AjaxPress and can break the Back button. The Navigation block’s script is kept, so mobile menus keep working. Return true to keep all of them. Default false.

add_filter( 'ajaxpress_keep_block_navigation', '__return_true' );

Settings

ajaxpress_settings

Filters the stored settings, merged over their defaults, wherever AjaxPress reads them.

ParameterTypeDescription
$settingsarraySettings, keyed by name
$options_from_dbarrayThe raw ajaxpress_* options, as stored

ajaxpress_public_settings

Filters the settings used on the front end, after ajaxpress_settings. Use it to force a value on a site without touching the saved settings:

// Always scroll new pages to the top, whatever the settings say.
add_filter( 'ajaxpress_public_settings', function ( $settings ) {
	$settings['scroll_to_top'] = true;
	return $settings;
} );

Setting names are listed in the settings reference, and match the keys in an exported settings file.

ajaxpress_default_options

Filters the default value of every setting. Add-ons use it to register their own settings.

ajaxpress_settings_schema

Every setting has a type, and a saved value is cleaned by its type. A value that doesn’t fit falls back to the setting’s default, and a setting without a type is dropped. Add-ons that store their own settings must declare them here:

add_filter( 'ajaxpress_default_options', function ( $defaults ) {
	$defaults['myaddon_accent'] = '#e11d48';
	return $defaults;
} );

add_filter( 'ajaxpress_settings_schema', function ( $schema ) {
	$schema['myaddon_accent'] = array( 'type' => 'color' );
	return $schema;
} );

The types are bool, int, float, enum (with values), color, url, text, textarea, selectors, html_classes, html_id, css, css_length, duration, id_list and ref_list.

Front end

ajaxpress_frontend_vars

Filters the data handed to AjaxPress’s front-end script (the ajaxpress_vars object). Add your own values here for a module built on the JavaScript extension API:

add_filter( 'ajaxpress_frontend_vars', function ( $vars ) {
	$vars['my_addon'] = array( 'station' => 'live-radio' );
	return $vars;
} );

ajaxpress_inline_css

Filters the small stylesheet AjaxPress prints for its loader and cursor.

ParameterTypeDescription
$cssstringThe CSS

Lifecycle

ajaxpress_upgraded (action)

Fires once when the AjaxPress version on disk changes: after an update, a downgrade, or on a new install.

ParameterTypeDescription
$fromstringThe previous version, or an empty string on a new install
$tostringThe version now installed
add_action( 'ajaxpress_upgraded', function ( $from, $to ) {
	// Clear your own page cache after AjaxPress updates, for example.
}, 10, 2 );

Super Cache by Cloudflare (Pro)

These tune Super Cache by Cloudflare. Filters that change the cache rules (ajaxpress_cf_bypass_patterns, ajaxpress_cf_bypass_cookies and ajaxpress_cf_edge_ttl) reach Cloudflare the next time AjaxPress syncs its settings there, for example when you next change something on the Cache tab.

FilterValueDefaultWhat it controls
ajaxpress_cf_bypass_patternsarray of path prefixes/wp-admin, /wp-json, /wp-login, /checkout, /cartPaths that are never cached
ajaxpress_cf_bypass_cookiesarray of cookie name fragmentswordpress_logged_in_, woocommerce_, wp_woocommerce_session_, edd_, comment_author_, wordpress_sec_Visitors with a matching cookie always bypass the cache
ajaxpress_cf_edge_ttlint, seconds3600How long a page stays cached at the edge
ajaxpress_cf_purge_post_urlsarray of URLs, plus $post_idThe post, home page, archive, categories, tags, authorWhat is purged when a post is published or updated
ajaxpress_cf_auto_purgebooltruePurging on edit. Turn it off only if you purge yourself
ajaxpress_cf_warm_seed_urlsarray of URLs, plus the cache objectKey pagesPages cached first after connecting
ajaxpress_cf_warm_daily_budgetint900How many pages a day the background fill may cache
ajaxpress_cf_kv_pagesbooltrue when availableThe globally replicated copy of pages (“Global layer”)
// Keep a members area out of the edge cache, and cache pages for six hours.
add_filter( 'ajaxpress_cf_bypass_patterns', function ( $patterns ) {
	$patterns[] = '/members';
	return $patterns;
} );
add_filter( 'ajaxpress_cf_edge_ttl', function () {
	return 6 * HOUR_IN_SECONDS;
} );

// Also purge a custom landing page whenever a post changes.
add_filter( 'ajaxpress_cf_purge_post_urls', function ( $urls, $post_id ) {
	$urls[] = home_url( '/latest/' );
	return $urls;
}, 10, 2 );