Skip to content

Instantly share code, notes, and snippets.

View jdevalk's full-sized avatar
😀

Joost de Valk jdevalk

😀
View GitHub Profile

If you use HelpScout's Docs product, you want to be able to search that Docs site when you're creating links in your WordPress install. Using the Better Internal Link Search plugin and this piece of code, you can. It'll look like this:

Docs search

Add the code below to one of your must use plugins, or even insert it as a single plugin on its own:

@jdevalk
jdevalk / logging-helper.php
Last active December 9, 2021 16:25
This little hack enables fatal error logging for your site, without creating an error log that is insanely big.
<?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 / gist:ca4fefd3a3122e86ce49
Created April 22, 2015 07:31
This gist allows you to prevent the redirect to the about page, the intro tour from showing up and the tracking popup from ever showing.
<?php
/**
* Filter the contents of the WP SEO option
*
* @param array $option The WP SEO main option values
*
* @return array
*/
function filter_yst_wpseo_option( $option ) {
@jdevalk
jdevalk / gist:c06834fb4e8c9953a563
Last active October 9, 2018 05:28
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.
<?php
/**
* Replace image URIs with CDN image URIs
*
* @param string $uri
*
* @return string
*/
function yst_cdn_filter( $uri ) {
@jdevalk
jdevalk / yoast-glotpress-seo.php
Last active August 9, 2016 21:24
Small SEO plugin for GlotPress
<?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 );
}
@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 / 1 Server block
Last active August 29, 2015 14:05
NGINX config for @dannyvankooten's EDD SL API Endpoint code
if ( $query_string ~ "^edd_action=" ) {
set $edd_api 1;
}
if ( $request_uri ~ "^/edd-sl-api" ) {
set $edd_api 2;
}
if ( $edd_api = 1 ) {
return 307 https://example.com/edd-sl-api$request_uri;
}
@jdevalk
jdevalk / no-widgets-for-xml.php
Created June 4, 2014 11:49
When loading an XML sitemap, WordPress still does a number of queries for all the widgets, if I did this in WordPress SEO, do you think that'd "kill" things?
<?php
if ( isset( $_SERVER['REQUEST_URI'] ) && in_array( substr( $_SERVER['REQUEST_URI'], -4 ), array( '.xml', '.xsl' ) ) ) {
remove_all_actions( 'widgets_init' );
}
<?php
/**
* Make the `vc_raw_html` shortcodes content available to the video seo plugin for indexing.
*
* @param string $content The post content
*
* @return string
*/
function yst_make_raw_html_detectable( $content ) {
<!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++) {