Skip to content

Instantly share code, notes, and snippets.

Avatar

Joost de Valk jdevalk

View GitHub Profile
@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 / 1 Server block
Last active Aug 29, 2015
NGINX config for @dannyvankooten's EDD SL API Endpoint code
View 1 Server block
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 Jun 4, 2014
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?
View no-widgets-for-xml.php
<?php
if ( isset( $_SERVER['REQUEST_URI'] ) && in_array( substr( $_SERVER['REQUEST_URI'], -4 ), array( '.xml', '.xsl' ) ) ) {
remove_all_actions( 'widgets_init' );
}
View raw_html_filter.php
<?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 ) {
View snippet-test.html
<!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 / 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 / gist:6635587
Last active Dec 23, 2015
How to die(); without NextGen Gallery annoying you with more output.
View gist:6635587
<?php
/**
* Prevent stupid plugins from running shutdown scripts when we're obviously not outputting HTML.
*/
function really_die() {
global $wp_filter;
unset( $wp_filter['wp_footer'], $wp_filter['shutdown'] );
$wp_filter['wp_footer'] = 1;
die();
}
@jdevalk
jdevalk / gist:6234102
Last active Dec 21, 2015
Make EDD work with NGINX
View gist:6234102
<?php
/**
* Make sure EDD doesn't trip over the NGINX values of global server settings and returns the proper current page URL.
*
* @param string $url The current page URL
* @return string The fixed current page URL.
*/
function yst_fix_edd_current_page_url( $url ) {
if ( is_front_page() ) :
$page_url = home_url();
@jdevalk
jdevalk / EDD_AJAX_non_ssl_filter.php
Created Aug 14, 2013
Make sure the AJAX URL for EDD uses the protocol for the current page, either http or https, as it doesn't work otherwise.
View EDD_AJAX_non_ssl_filter.php
<?php
/**
* Make sure the AJAX URL for EDD uses the protocol for the current page, either http or https, as it doesn't work otherwise.
*
* @param string $ajaxurl The current ajaxurl
*
* @return string
*/
function yst_filter_edd_ajax_url( $ajaxurl ) {
@jdevalk
jdevalk / discount_url.php
Created Aug 14, 2013
Allow specification of a discount coupon through the URL, this means we can do away with the coupon field in the checkout process.
View discount_url.php
<?php
/**
* Allow people to specify a coupon code in the URL, and add it to their cart.
*/
function yst_edd_discount_link() {
if ( isset( $_GET['coupon'] ) ) {
// Check whether it's a valid coupon, if so, add it to the cart.
if ( edd_is_discount_valid( $_GET['coupon'] ) )
edd_set_cart_discount( $_GET['coupon'] );