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 / 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')));
@wp-seopress
wp-seopress / remove-seopress-widgets-from-dashboard.php
Last active March 14, 2024 09:52
Remove SEOPress dashboard widgets
add_action('wp_dashboard_setup', 'sp_remove_dashboard_widgets' );
function sp_remove_dashboard_widgets() {
remove_meta_box( 'seopress_ga_dashboard_widget', 'dashboard', 'normal' );
remove_meta_box( 'seopress_insights_dashboard_rankings_widget', 'dashboard', 'normal' );
remove_meta_box( 'seopress_matomo_dashboard_widget', 'dashboard', 'normal' );
}
@wp-seopress
wp-seopress / filter-export-404-errors-query.php
Created January 30, 2024 16:32
Filter export 404 errors query
add_filter('seopress_export_404_query', 'sp_export_404_query');
function sp_export_404_query($args) {
$args = [
'post_type' => 'seopress_404',
'posts_per_page' => '-1',
'meta_query' => [
[
'key' => '_seopress_redirections_type',
'compare' => 'NOT EXISTS',
],
@wp-seopress
wp-seopress / filter-single-taxonomy-xml-sitemap-query.php
Last active January 30, 2024 15:04
Filter single taxonomy XML sitemap query
function sp_sitemaps_single_term_query($args, $tax) {
//Default Query
//$args = [
// 'taxonomy' => $tax,
// 'offset' => $offset,
// 'hide_empty' => true,
// 'number' => 1000,
// 'fields' => 'ids',
// 'lang' => ''
//];
@wp-seopress
wp-seopress / multidomain-xml-sitemap-with-polylang-and-seopress.php
Last active December 18, 2023 15:24
Multidomain XML sitemap with Polylang and SEOPress
//POLYLANG MULTI-DOMAIN
add_filter( 'seopress_sitemaps_home_url', 'sp_sitemaps_home_url' );
function sp_sitemaps_home_url($home_url) {
if (function_exists('pll_home_url')) {
$home_url = pll_home_url();
}
return $home_url;
}
function sp_sitemaps_single_query($args, $cpt_key) {
@wp-seopress
wp-seopress / filter-the-arguments-sent-to-openai-to-generate-alternative-texts.php
Created December 11, 2023 14:37
Filter the arguments sent to OpenAI to generate alternative texts
add_filter('seopress_ai_openai_request_args_alt', 'sp_ai_openai_request_args_alt');
function sp_ai_openai_request_args_alt($args) {
//do your stuff, this is just an example
//var_dump($body)
$args = [
'body' => json_encode($body),
'timeout' => '30',
'redirection' => '5',
@wp-seopress
wp-seopress / force-the-display-of-the-custom-post-type-archive-page-even-if-it-does-not-exist-in-breadcrumbs.php
Last active December 7, 2023 08:47
Force the display of the custom post type archive page even if it does not exist in breadcrumbs
add_filter('seopress_breadcrumbs_force_archive_name', '__return_true');
//has_archive must be set to TRUE in the register post type function
@wp-seopress
wp-seopress / filter-breadcrumbs-json.php
Created December 6, 2023 14:50
Filter Breadcrumbs JSON
add_filter( 'seopress_pro_breadcrumbs_json', 'sp_pro_breadcrumbs_json' );
function sp_pro_breadcrumbs_json($array) {
//var_dump($array);
//do your stuff
return $array;
}
@wp-seopress
wp-seopress / filter-the-video-xml-sitemap-regeneration-tool.php
Created November 9, 2023 15:46
Filter the video XML sitemap regeneration tool
function sp_video_regeneration_total_count_posts($sql) {
global $wpdb;
$sql = (int) $wpdb->get_var("SELECT count(*) FROM {$wpdb->posts} WHERE post_status IN ('pending', 'draft', 'publish', 'future') AND post_type IN ( 'your_cpt_name' ) ");
return $sql;
}
add_filter('seopress_video_regeneration_total_count_posts', 'sp_video_regeneration_total_count_posts');
function sp_video_regeneration_increment($increment) {
//default: 1