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 / automatic-product-schema-seopress-pro.php
Last active January 2, 2025 09:08
Add "MerchantReturnPolicy" and "deliveryTime" to each product offer for the automatic product schema with SEOPress PRO
<?php
//Add "MerchantReturnPolicy" and "deliveryTime" to each product offer for the automatic product schema with SEOPress PRO
add_filter('seopress_schemas_auto_product_json', 'sp_schemas_auto_product_json');
function sp_schemas_auto_product_json($json) {
// Check if 'offers' exists in the JSON
if (!isset($json['offers'])) {
return $json;
}
// Get the product offers
@wp-seopress
wp-seopress / kk-star-ratings-seopress-pro-schemas.php
Last active December 20, 2024 08:37
Integrate KK Star Ratings with SEOPress PRO schemas
// This snippet will retrieve the votes from the current post handled by KK Star Ratings plugin
add_filter('seopress_schemas_auto_recipe_json', 'sp_schemas_auto_recipe_json');
function sp_schemas_auto_recipe_json($json) {
$post_id = get_the_ID();
$rating_data = get_post_meta($post_id, '_kksr_avg_default', true);
$count = get_post_meta($post_id, '_kksr_count_default', true);
if (!empty($rating_data) && !empty($count)) {
$json['aggregateRating'] = [
@wp-seopress
wp-seopress / post-meta-fields-jetengine-automatic-schemas-seopress.php
Last active November 28, 2024 18:20
Add predefined dynamic variables from Jet Engine to SEOPress' schemas
<?php
add_filter('seopress_schemas_mapping_select', 'sp_schemas_mapping_select');
function sp_schemas_mapping_select($select) {
//Add the new group option + option to the list
$select['Jet Engine'] = [
'my_new_dynamic_variable_key' => __('My new dynamic variable title', 'wp-seopress-pro'),
];
return $select;
}
@wp-seopress
wp-seopress / post-meta-fields-jetengine-seopress.php
Last active November 28, 2024 18:20
Use post meta fields from a JetEngine custom table and SEOPress
<?php
function sp_titles_template_variables_array($array) {
$array[] = '%%my-custom-global-variable%%';
return $array;
}
add_filter('seopress_titles_template_variables_array', 'sp_titles_template_variables_array');
function sp_titles_template_replace_array($array) {
// Replace my_jetengine_custom_field with the name of your meta field (to be used with custom database storage)
$array[] = esc_attr(wp_strip_all_tags( jet_engine()->listings->data->get_meta( 'my_jetengine_custom_field' ) ));
return $array;
@wp-seopress
wp-seopress / run-action-after-site-audit-is-completed.php
Created October 28, 2024 09:35
Run action after site audit is completed
add_action('seopress_site_audit_after_processs', 'sp_site_audit_after_processs');
function sp_site_audit_after_processs() {
//do something
}
@wp-seopress
wp-seopress / filter-post-object-sent-automatically-to-indexnow-api.php
Last active October 10, 2024 12:49
Filter post object sent automatically to IndexNow API
add_filter('seopress_instant_indexing_permalink', 'sp_instant_indexing_permalink', 10, 2);
function sp_instant_indexing_permalink($permalink, $post) {
$cpt = get_post_type( $post ) ? get_post_type( $post ) : '';
if ($cpt === 'test') {
return false;
}
return $permalink;
}
@wp-seopress
wp-seopress / filter-the-tabs-of-the-site-overview-dashboard-block.php
Last active October 8, 2024 09:03
Filter tabs in the Dashboard Site Overview block
add_filter('seopress_dashboard_site_overview_tabs', 'sp_dashboard_site_overview_tabs');
function sp_dashboard_site_overview_tabs($tabs) {
//Default array
// $tabs = [
// 'tab_seopress_analytics' => esc_html__('Google Analytics', 'wp-seopress-pro'),
// 'tab_seopress_matomo' => esc_html__('Matomo Analytics', 'wp-seopress-pro'),
// 'tab_seopress_ps' => esc_html__('PageSpeed', 'wp-seopress-pro'),
// 'tab_seopress_gsc' => esc_html__('Search Console', 'wp-seopress-pro'),
// ];
@wp-seopress
wp-seopress / filter-the-query-of-the-site-audit-feature.php
Last active October 28, 2024 09:39
Filter the query of the Site Audit feature
<?php
add_filter('seopress_site_audit_query', 'sp_site_audit_query', 10, 5);
function sp_site_audit_query($args, $batch_size, $offset, $cpt, $cpt_status) {
//Pass your WP Query arguments to the $args array
//default values
$args = [
'posts_per_page' => $batch_size,
'offset' => (int)$offset,
'post_type' => $cpt,
'post_status' => $cpt_status,
@wp-seopress
wp-seopress / filter-google-news-name-for-xml-news-sitemap.php
Created September 2, 2024 14:03
Filter Google News Name for XML News Sitemap
add_filter('seopress_sitemaps_xml_news_name', 'sp_sitemaps_xml_news_name');
function sp_sitemaps_xml_news_name($name) {
$name = 'My Google News Name';
return $name;
}
@wp-seopress
wp-seopress / seopress-defer-scripts.php
Created August 10, 2024 14:34
SEOPress.org defer scripts
<?php
//Defer JS
add_filter('script_loader_tag', 'seopress_add_async_defer', 10, 3);
function seopress_add_async_defer($tag, $handle, $src)
{
$defer_scripts = array(
'global-scripts'
);
if (in_array($handle, $defer_scripts)) {