Skip to content

Instantly share code, notes, and snippets.

View wp-seopress's full-sized avatar
😊
Coding SEOPress, best WordPress SEO plugin

Benjamin Denis wp-seopress

😊
Coding SEOPress, best WordPress SEO plugin
View GitHub Profile
@wp-seopress
wp-seopress / seopress-variable-font.css
Created August 10, 2024 13:43
SEOPress.org variable font
@font-face {
font-family: 'Inter';
font-style: normal;
font-weight: 300 700;
font-display: swap;
src: url(https://www.seopress.org/wp-content/themes/blackhat/assets/fonts/inter.woff2) format('woff2');
}
@wp-seopress
wp-seopress / seopress-preload-resources.php
Created August 10, 2024 13:34
SEOPress.org preload resources
<?php
//Preload resources
add_filter('wp_resource_hints', 'seopress_resource_hints', 10, 2);
function seopress_resource_hints($urls, $relation_type)
{
if (wp_style_is('degular-font', 'queue') && 'preconnect' === $relation_type) {
$urls[] = array(
'href' => 'https://use.typekit.net',
'crossorigin',
);
@wp-seopress
wp-seopress / seopress-async-webfonts.php
Created August 10, 2024 13:31
SEOPress.org async webfonts
<?php
//Async CSS
add_filter('style_loader_tag', 'seopress_add_stylesheet_attributes', 10, 2);
function seopress_add_stylesheet_attributes($html, $handle)
{
$styles = array(
'fonts',
'degular-font',
);
@wp-seopress
wp-seopress / seopress-transients-navigation-menus.php
Created August 10, 2024 13:21
SEOPress.org transients for navigation menus
<?php
$transient = get_transient( 'seopress_main_menu' );
if ( false === $transient) {
ob_start();
get_template_part('template-parts/block/cache/main', 'menu');
$cache = ob_get_contents();
ob_end_clean();
set_transient('seopress_main_menu', $cache, 24 * HOUR_IN_SECONDS);
@wp-seopress
wp-seopress / seopress-expires-headers.txt
Last active August 10, 2024 13:23
SEOPress.org expires headers
# BEGIN Cache
# Use UTF-8 encoding for anything served text/plain or text/html
AddDefaultCharset UTF-8
# Force UTF-8 for a number of file formats
<IfModule mod_mime.c>
AddCharset UTF-8 .atom .css .js .json .rss .vtt .xml
</IfModule>
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
@wp-seopress
wp-seopress / filter-fediverse-creator-tag.php
Created July 11, 2024 13:39
Filter fediverse creator tag
function sp_social_fv_creator($html) {
//do your stuff here
//<meta name="fediverse:creator" content="@[email protected]" />
return $html;
}
add_filter('seopress_social_fv_creator', 'sp_social_fv_creator');
function sp_rgpd_full_message($user_msg, $edit_cookie_btn) {
return '<div id="my-cookie-bar">'.$user_msg.$edit_cookie_btn.'</div>';
}
add_filter('seopress_rgpd_edit_message', 'sp_rgpd_full_message', 10, 2);
@wp-seopress
wp-seopress / filter-the-post-date-format-in-html-sitemap.php
Created May 20, 2024 11:57
Filter the post date format in HTML sitemap
add_filter('seopress_sitemaps_html_post_date_format', 'sp_sitemaps_html_post_date_format');
function sp_sitemaps_html_post_date_format($date_format) {
$date_format = 'j F Y';
return $date_format;
}
@wp-seopress
wp-seopress / how-to-solve-missing-fields-errors-in-google-structured-data-types-schemas.php
Created April 25, 2024 15:05
How to solve "missing fields" errors in Google Structured Data Types (schemas) - eg with product schema
add_filter('seopress_schemas_auto_product_json', 'sp_schemas_auto_product_json');
function sp_schemas_auto_product_json($json) {
// Returns schema as an array with 'property' => 'value'
// Get the product offers
$offers = $json['offers'];
// Add sub-type MerchantReturnPolicy and deliveryTime to each offer
if (!empty($offers)) {
foreach ($offers as $key => $offer) {
@wp-seopress
wp-seopress / dynamic-variables-acf-options-page-for-seopress.php
Created April 10, 2024 15:57
Create a dynamic variable from Advanced Custom Fields options page for SEOPress metadata
function sp_titles_template_variables_array($array) {
$array[] = '%%_acf_options_my_field_name%%';
$array[] = '%%_acf_options_my_field_name_2%%';
return $array;
}
add_filter('seopress_titles_template_variables_array', 'sp_titles_template_variables_array');
function sp_titles_template_replace_array($array) {
$array[] = esc_attr(wp_strip_all_tags(get_field('my_field_name', 'option')));