Skip to content

Instantly share code, notes, and snippets.

Avatar

Joost de Valk jdevalk

View GitHub Profile
@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 );
@jdevalk
jdevalk / regex.php
Created Jul 2, 2012
Regex to match meta description in content
View regex.php
<?php
preg_match_all( '#<meta (name|content)="(.*)" (name|content)="(.*)"(\s+)?/?>#i', $content, $matches, PREG_SET_ORDER );
preg_match_all( "#<meta (name|content)='(.*)' (name|content)='(.*)'(\s+)?/?>#i", $content, $matches2, PREG_SET_ORDER );
@jdevalk
jdevalk / gist:5411371
Created Apr 18, 2013
NGINX rewrites for WordPress SEO XML Sitemaps
View gist:5411371
# Rewrites for WordPress SEO XML Sitemap
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
@jdevalk
jdevalk / changelog-1.2.md
Created May 28, 2012
Changelog for WP SEO 1.2
View changelog-1.2.md

If you want to help test, you can download the development version from here, or directly from here. If you find issues, please file them here.

= 1.2 (development version) =

Major improvements: all sorts of fixes to suggest and keyword check functionality which now should allow for non-ascii stuff, like Greek, Arabic, but even "weird" chars in western-European languages.

  • Bugs fixed:
    • ereg_replace != preg_replace ; in other words: alt and title tags for images in xml sitemap fixed.
    • Image size for OpenGraph now defaults to medium for thumbnail image.
    • Selecting a Facebook App as the admin of your site now actually works.
@jdevalk
jdevalk / gist:c06834fb4e8c9953a563
Last active Oct 9, 2018
Snippet to replace image URIs with CDN image URIs in the XML sitemaps generated by WordPress SEO by Yoast. Obviously replace yoast.com with whatever is your site's domain.
View gist:c06834fb4e8c9953a563
<?php
/**
* Replace image URIs with CDN image URIs
*
* @param string $uri
*
* @return string
*/
function yst_cdn_filter( $uri ) {
@jdevalk
jdevalk / gist:1500757
Created Dec 20, 2011
Gravity Forms API
View gist:1500757
<?php
// Add a search to filter the entires, the form_id is the form ID you see in the GET variable on the entries or edit page
$search = "";
$form_id = 4;
// Authentication (add a username if you want for more security)
if ( ! isset($_GET['key']) || $_GET['key'] != '<set an API Key>' )
die;
@jdevalk
jdevalk / svgs.md
Last active Jul 13, 2018
What to do with SVG's
View svgs.md

Regex search:

  • style=(["|'])fill:#([a-zA-Z0-9]{3,});\1 replace with fill="#$2"
  • (class|id)=(["|'])([a-zA-Z_0-9-^-]+)\2 replace with blank

In a nuttshell:

  • Remove <title> and <decoration> if the image is “just decoration”.
  • Add role="img" aria-hidden="true" focusable="false" to the svg. Exclude aria-hidden="true" if its an infographic.
  • If its important to understand the “svg” in order to understand what the page is about, use aria-labelledby="title desc" on the SVG and use <title> and <desc> element in the SVG.
@jdevalk
jdevalk / archive-wpseo_locations.php
Created Dec 3, 2013
Easily create a custom post type archive page such as demoed on [the Yoast Local SEO demo site](http://local.yoastdemo.com/locations/) using this file:
View archive-wpseo_locations.php
<?php
/** Replace the standard loop with our custom Locations loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'wpseo_locations_archive_loop' );
function wpseo_locations_archive_loop() {
echo '<h1>Locations</h1>';
echo '<div class="entry-content"><p>Your intro text here.</p></div>';
$args = array(
@jdevalk
jdevalk / yoast-glotpress-seo.php
Last active Aug 9, 2016
Small SEO plugin for GlotPress
View yoast-glotpress-seo.php
<?php
class Yoast_GlotPress_SEO {
function __construct() {
add_filter( 'gp_title', array( $this, 'modify_title' ) );
add_action( 'gp_head', array( $this, 'meta_desc' ), 9 );
add_filter( 'gp_redirect_status', array( $this, 'modify_redirect_status' ), 10, 2 );
}