Skip to content

Instantly share code, notes, and snippets.

View jdevalk's full-sized avatar
😀

Joost de Valk jdevalk

😀
View GitHub Profile
@jdevalk
jdevalk / post_excerpt.php
Last active July 2, 2025 16:18
If you have the YouTube code in your post excerpt, this will fix it.
<?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 / archive-wpseo_locations.php
Created December 3, 2013 11:31
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:
<?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(
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<script type="text/javascript">
function showGTitle() {
var gText1 = document.getElementById('gtext1pete').value;
var gBold1 = document.getElementById('gbold1pete').value;
var gWords1 = gBold1.split(' ');
for(var gI1=0; gI1<gWords1.length; gI1++) {
@jdevalk
jdevalk / gist:5465432
Created April 26, 2013 06:55
Add excerpt to the content to be scanned by the WP SEO Video plugin
<?php
function fix_content_input( $content, $vid ) {
$post = get_post( $vid['post_id'] );
if ( !empty( $post->post_excerpt ) )
$content = "\n" . $post->post_excerpt . "\n" . $content;
return $content;
}
add_filter( 'wpseo_video_index_content', 'fix_content_input', 10, 2 );
@jdevalk
jdevalk / archive-wpseo_locations.php
Last active July 2, 2025 14:57
A cool example of what your locations post type archive page could look like
<?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 October 1, 2014 09:08
Change WP SEO JSON+LD search URL from ?s= to /search/
<?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 / author-itemprop.php
Last active July 2, 2025 13:58
Bits of schema that require non-schema filters right now, for which I've written these functions
<?php
// For pages where you'd rather not have 20 rel=authors and in fact *do* need itemprop=author
// For instance on http://yoast.com/review/
function yoast_author_schema( $output ) {
return str_replace( 'rel="author"', 'itemprop="author"', $output );
}
add_filter( 'genesis_post_author_posts_link_shortcode', 'yoast_author_schema', 20 );
@jdevalk
jdevalk / archive-speaking_event.php
Last active July 2, 2025 13:58
Genesis helper code for schema
<?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 / README.md
Last active January 21, 2025 12:11
The Events Calendar SEO fix

The Events Calendar SEO fix

This plugin fixes the horrible SEO mess that The Events Calendar can create.

The Events Calendar has been an SEO problem for ages, and I've reported these issues to them numerous times over the years. They have made some fixes, but it's still not enough and especially on a site that has been running TEC for a long time, the fixes are not good enough, as the problems are hidden, but not fixed.

Problems:

  • If you disable "day" or "month" views in the settings (on by default), those don't get linked, but they still work...
  • If you enable the month view cache (on by default), months without events are only noindex-ed on the first view of that page, when they're cached they no longer get noindex-ed. This plugin solves that by disabling this cache.
<?php
class Joost_Comment_Fixes {
public function __construct() {
// Unhook comment cookies stuff from core.
remove_action( 'set_comment_cookies', 'wp_set_comment_cookies' );
add_action( 'wp_footer', [ $this, 'print_custom_comment_script' ] );
add_filter( 'wp_get_current_commenter', [ $this, 'ignore_comment_cookies_serverside' ] );
add_filter( 'comment_post_redirect', [ $this, 'comment_moderation_redirect' ], 10, 2 );