Skip to content

Instantly share code, notes, and snippets.

Avatar

Joost de Valk jdevalk

View GitHub Profile
@jdevalk
jdevalk / .htaccess
Last active Oct 4, 2021
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 / 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 / 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.
*/
@jdevalk
jdevalk / logging-helper.php
Last active Feb 27, 2020
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.
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",
@jdevalk
jdevalk / gist:1565059
Created Jan 5, 2012
oembed function to use content_width appropriately
View gist:1565059
<?php
function yoast_oembed_dataparse( $html, $data, $url ) {
global $content_width;
preg_match( '/width="(\d+)"/', $html, $matches );
$width = $matches[1];
preg_match( '/height="(\d+)"/', $html, $matches );
$height = $matches[1];
$aspect_ratio = $width / $height;
@jdevalk
jdevalk / post_excerpt.php
Last active Feb 9, 2019
If you have the YouTube code in your post excerpt, this will fix it.
View post_excerpt.php
<?php
function fix_content_input( $content, $vid ) {
$post = get_post( $vid['post_id'] );
if ( !empty( $post->post_excerpt ) ) {
$content = "\n" . 'http://youtube.com/v/'. $post->post_excerpt . "\n" . $content;
}
return $content;
}
add_filter( 'wpseo_video_index_content', 'fix_content_input', 10, 2 );