Skip to content

Instantly share code, notes, and snippets.

Avatar

Joost de Valk jdevalk

View GitHub Profile
@jdevalk
jdevalk / pinterest.php
Created Apr 16, 2012
Pinterest button shortcode
View pinterest.php
<?php
// Usage [pin img="<url>" title="<title>"]
function yoast_pinterest_shortcode( $atts ) {
extract( shortcode_atts( array(
'url' => get_permalink(),
'img' => '',
'title' => get_the_title(),
'align' => 'alignright'
@jdevalk
jdevalk / dev-environment.php
Created Jul 23, 2015
Throw this in your dev environments mu-plugins folder and add it to your .gitignore file :)
View dev-environment.php
<?php
/**
* Disables plugins on your dev environment
*
* @param $plugins
*
* @return mixed
*/
function yst_dev_env_disable_plugins( $plugins ) {
@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 / 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'] );
@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 ) {
View gist:5917169
<?php
/**
* Enable qTranslate for WordPress SEO
*
* @param string $text The string to translate
*
* @return string
*/
function qtranslate_filter( $text ) {
@jdevalk
jdevalk / functions.php
Last active Dec 18, 2015
Pushes the WordPress SEO metabox below the ACF metabox. Put the code below in your theme's functions.php or in your functionality plugin:
View functions.php
<?php
/**
* Adds a bit of JS that moves the meta box for WP SEO below the ACF box.
*/
function move_yoast_seo_below_acf_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
if ( $('.acf_postbox').length > 0 && $('#wpseo_meta').length > 0 ) {
@jdevalk
jdevalk / author-itemprop.php
Last active Dec 17, 2015
Bits of schema that require non-schema filters right now, for which I've written these functions
View author-itemprop.php
<?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 );
View WPSEO Function Example.php
<?php
/**
* Example function description
*
* @since {Next WordPress SEO Version}
*
* @param {array, string, int, objext} {$variable_name} {Short description}
* @param {array, string, int, objext} {$variable_name} {Short description}
*