soflyy/oxygen-bugs-and-features

Add filter functions for Google Fonts link elements in head of html

Opened this issue · 0 comments

Describe the feature you'd like to see included in Oxygen.
A clear, detailed description of the feature you're requesting.

relevant plugin file: component-framework/component-init.php lines 4607 - 4636

Could you please add a filter function, so developers get the ability to manipulate Google Font URL in link stylesheet and Google Font server link preload output?

What are the use cases for this feature?
e.g. Accessibility, e-commerce store that sells bicycles, etc.

For GDPR reasons, oxygen driven websites, should not pull stylesheet or preload those from Google Servers.
Thus it would be super helpful, if you provided two simple filter functions, that would allow developers to manipulate provided stylesheet url and if needed disable that preload output all together in website frontend.
A filter function would allow this easily while still maintaining Google Font availablity in oxygen backend builder gui.

Examples of this feature or functionality.
If another product has done it well, provide examples here.

A solution could look like this:

// Defined by choice in Oxygen builder backend.
$family = 'Your_Font_Family_Name';

/**
 * Apply a filter to the stylesheet URL.
 *
 * This allows modification of the Google Font stylesheet URL dynamically. 
 * The filter name 'custom_stylesheet_url' can be used in themes or plugins 
 * to change the URL, for example, to point to a different font family or to modify the query parameters.
 */
$stylesheet_url = apply_filters('custom_stylesheet_url', 'https://fonts.googleapis.com/css?family=' . $family);

/**
 * Apply a filter to control the enabling of the preload link.
 *
 * This filter allows control over the output of the preload link tag. 
 * By default, the preload is enabled. The filter 'enable_preload_stylesheet' can be used 
 * to dynamically disable the output of the preload link tag in certain conditions.
 */
$enable_preload = apply_filters('enable_preload_stylesheet', true);

// Output the preload link tag if preload is enabled.
if ($enable_preload) {
    echo '<link rel="preload" as="style" href="' . esc_url($stylesheet_url) . '" >' . "\r\n";
}

// Output the stylesheet link tag.
echo '<link rel="stylesheet" href="' . esc_url($stylesheet_url) . '">' . "\r\n";

Now it would be super easy to make use of GDPR compliant url swaps via available filter functions.

Thanks for reading and considering my feature request!