Developer Docs

This part of the documentation contains a list of all available Action and Filter hooks in OMGF and OMGF Pro. Sorted alphabetically.

omgf_pro_fallback_font_aliases

Filter for the font names Magic Fallbacks recognizes. Magic Fallbacks finds a font by its family name. Is a font loaded under a different name than the one it’s known by on Google Fonts, e.g. an older name? Then map it to its current name, so it gets a Magic Fallback, too.

add_filter( 'omgf_pro_fallback_font_aliases', function ( $aliases ) {
    $aliases[ 'My Old Font Name' ] = 'Current Google Font Name';

    return $aliases;
} );
Code language: PHP (php)

omgf_pro_modify_source_url

Allows you to modify the source URL used in (inline) CSS stylesheets to your liking.

For example, if you’d like to use relative URLs:

add_filter('omgf_pro_modify_source_url', 'daan_dev_modify_source_url', 11);

function daan_dev_modify_source_url($url) {
    return str_replace(get_home_url(), '', wp_upload_dir()['baseurl'] . '/omgf');
}Code language: PHP (php)

omgf_pro_optimize_dynamic_css_handles

Some themes use a dynamic CSS generator to apply theme options to their stylesheets. This filter allows you to add your theme’s dynamic CSS handle, so it’ll be recognized as a stylesheet by OMGF Pro. For example:

add_filter('omgf_pro_optimize_dynamic_css_handles', 'daan_dev_add_css_handle');

function daan_dev_add_css_handle($handles) {
    return array_merge(['banana'], $handles);
}Code language: PHP (php)

Handles that’re included by default are:

  • action
  • load
  • custom-css

omgf_pro_smart_optimize_entry_deleted

Action that fires after a page’s Smart Optimize results (desktop and mobile) are deleted with Re-scan & optimize this page in the admin bar. It receives the page’s path. Use it, together with omgf_pro_smart_optimize_results_stored, to purge the page from a page cache Smart Optimize doesn’t support.

add_action( 'omgf_pro_smart_optimize_entry_deleted', function ( $path ) {
    my_cache_purge_url( home_url( $path ) ); // Replace with your cache's purge function.
} );
Code language: PHP (php)

omgf_pro_smart_optimize_excluded

Filter to exclude pages from Smart Optimize: excluded pages aren’t analyzed, and no results are applied to them. Useful for pages that are different for every visitor, e.g. a members area. It runs on the page itself, so conditional tags like is_page() can be used.

add_filter( 'omgf_pro_smart_optimize_excluded', function ( $excluded ) {
    return $excluded || is_page( 'members' );
} );
Code language: PHP (php)

omgf_pro_smart_optimize_host_approved

Action that fires after a font host is trusted for Smart Optimize‘s preloads, e.g. when you click Trust on the Dashboard. It receives the host, e.g. fonts.example.com. All Smart Optimize results are deleted after this, so pages are analyzed again with the new list of trusted hosts.

omgf_pro_smart_optimize_host_revoked

Action that fires after a font host is removed from Smart Optimize‘s trusted hosts. It receives the host. Like omgf_pro_smart_optimize_host_approved, all results are deleted after this.

omgf_pro_smart_optimize_multi_tenant_domains

Filter for the list of shared hosting domains, e.g. amazonaws.com or b-cdn.net. On these domains, many unrelated sites get their own subdomain. So Smart Optimize only trusts the exact host you trusted there, not every other subdomain of that domain. Add a domain if your fonts come from a similar shared service.

add_filter( 'omgf_pro_smart_optimize_multi_tenant_domains', function ( $domains ) {
    $domains[] = 'shared-cdn.example';

    return $domains;
} );
Code language: PHP (php)

omgf_pro_smart_optimize_path

Filter for the path Smart Optimize stores a page’s results for, e.g. /blog/hello-world/. Use it to remove personal data from a URL, or to let similar pages share their results. It must return a path starting with /, otherwise it’s ignored. Page caches are only purged for the returned path.

add_filter( 'omgf_pro_smart_optimize_path', function ( $path ) {
    // Store /members/jane/ and /members/john/ as /members/.
    return preg_replace( '#^/members/[^/]+/#', '/members/', $path );
} );
Code language: PHP (php)

omgf_pro_smart_optimize_results_stored

Action that fires after Smart Optimize has stored a page’s results. It receives the page’s path, and whether the results are for mobile (1) or desktop (0). Use it to purge the page from a page cache Smart Optimize doesn’t support, so the next visitor gets the optimized version.

add_action( 'omgf_pro_smart_optimize_results_stored', function ( $path, $is_mobile ) {
    my_cache_purge_url( home_url( $path ) ); // Replace with your cache's purge function.
}, 10, 2 );
Code language: PHP (php)

omgf_pro_smart_optimize_trusted_preload_hosts

Filter to trust font hosts for Smart Optimize‘s preloads, without approving them on the Dashboard. Useful if you deploy the same setup to many sites.

add_filter( 'omgf_pro_smart_optimize_trusted_preload_hosts', function ( $hosts ) {
    $hosts[] = 'fonts.example.com';

    return $hosts;
} );
Code language: PHP (php)

omgf_pro_webfont_loader_search_replace_regex_async


omgf_pro_webfont_loader_search_replace_regex


omgf_settings

Using this filter allows you to override settings values, before they’re being output to the plugin.

omgf_setting_${name} (option_name)

Using this filter allows you to force a value for any option_name .