Skip to content

Instantly share code, notes, and snippets.

Avatar

Joost de Valk jdevalk

View GitHub Profile
@jdevalk
jdevalk / gist:5623050
Created May 21, 2013
Redirect script sample NGINX code. Make sure this location line sits above the "location /" code in your NGINX config.
View gist:5623050
location /redirect/ {
rewrite ^/redirect/(.*)$ /redirect/index.php?id=$1 last;
}
@jdevalk
jdevalk / .htaccess
Last active Apr 9, 2022
These three files together form an affiliate link redirect script.
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
</IfModule>
@jdevalk
jdevalk / copyrightholder.php
Last active Jan 6, 2022
This is how to add the copyrightHolder schema to the Website Schema piece Yoast SEO outputs.
View copyrightholder.php
<?php
add_filter( 'wpseo_schema_website', 'example_change_website_schema', 10, 2 );
/**
* Changes the Yoast SEO Website schema.
*
* @param array $data The Schema Website data.
* @param Meta_Tags_Context $context Context value object.
*
@jdevalk
jdevalk / archive-speaking_event.php
Last active Dec 12, 2021
Genesis helper code for schema
View archive-speaking_event.php
<?php
add_filter( 'genesis_attr_content', 'yoast_schema_empty', 20 );
add_filter( 'genesis_attr_entry', 'yoast_schema_event', 20 );
add_filter( 'genesis_attr_entry-title', 'yoast_itemprop_name', 20 );
add_filter( 'genesis_attr_entry-content', 'yoast_itemprop_description', 20 );
add_filter( 'genesis_post_title_output', 'yoast_title_link_schema', 20 );
/**
* We'll use the post info output to add more meta data about the event.
@jdevalk
jdevalk / logging-helper.php
Last active Dec 9, 2021
This little hack enables fatal error logging for your site, without creating an error log that is insanely big.
View logging-helper.php
<?php
/**
* This changes logging to only log fatal errors. This file should go in your mu-plugins directory.
*/
// Set the error logging to only log fatal errors
error_reporting( E_ERROR );
// Optional: change the location of your error log, it might be wise to put it outside your WP content dir.
// If you don't change it, the default place for this log is debug.log in your WP_CONTENT_DIR.
@jdevalk
jdevalk / register-graph-piece.php
Created Jan 22, 2020
This is the code used to generate the Event Schema for YoastCon
View register-graph-piece.php
<?php
/**
* Adds Schema pieces to our output.
*
* @param array $pieces Graph pieces to output.
* @param \WPSEO_Schema_Context $context Object with context variables.
*
* @return array $pieces Graph pieces to output.
*/
View gist:5318003
# WordPress SEO - XML Sitemap Rewrite Fix - for subfolder install
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^sitemap_index.xml$ /wordpress/index.php?sitemap=1 [L]
RewriteRule ^locations.kml$ /wordpress/index.php?sitemap=wpseo_local_kml [L]
RewriteRule ^geo_sitemap.xml$ /wordpress/index.php?sitemap=wpseo_local [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /wordpress/index.php?sitemap=$1&sitemap_n=$2 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix
@jdevalk
jdevalk / archive-wpseo_locations.php
Last active Jul 14, 2019
A cool example of what your locations post type archive page could look like
View archive-wpseo_locations.php
<?php
/**
* Template for displaying a map on the locations post-type archive page.
*
* @package Twenty_Twelve
* @subpackage Local SEO for WordPress Archive page template
* @author Joost de Valk
*/
get_header();
@jdevalk
jdevalk / gist:0b2ddd13d27cf869a976
Created Oct 1, 2014
Change WP SEO JSON+LD search URL from ?s= to /search/
View gist:0b2ddd13d27cf869a976
<?php
/**
* Changes the search slug to /search/ for the JSON+LD output
*/
function yst_change_json_ld_search_url() {
return trailingslashit( home_url() ) . 'search/{search_term}';
}
add_filter( 'wpseo_json_ld_search_url', 'yst_change_json_ld_search_url' );
@jdevalk
jdevalk / two-products-best.json
Last active May 7, 2019
Two JSON blobs, one with the main product, a second one that can be output later on the page that clearly relates itself to the first one as a related product.
View two-products-best.json
<script type="application/ld+json">{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://example.com/#organization",
"name": "Yoast",
"url": "https://example.com/",
"sameAs": [
"https://www.facebook.com/yoast",