Skip to content

Instantly share code, notes, and snippets.

View brianleejackson's full-sized avatar
✍️
Writing

Brian Jackson brianleejackson

✍️
Writing
View GitHub Profile
@brianleejackson
brianleejackson / gp-disable-google-fonts.php
Last active September 4, 2017 23:17
gp-disable-google-fonts
add_action( 'wp_enqueue_scripts','tu_remove_google_fonts', 10 );
function tu_remove_google_fonts() {
wp_dequeue_style( 'generate-fonts' );
}
@brianleejackson
brianleejackson / gp-yoast-seo-cdn.php
Last active March 14, 2018 02:00
gp-yoast-seo-cdn
function wpseo_cdn_filter( $uri ) {
return str_replace( 'https://domain.com', 'https://cdn.domain.com', $uri );
}
add_filter( 'wpseo_xml_sitemap_img_src', 'wpseo_cdn_filter' );
@generatepress
generatepress / gist:8bc94ae43f67c40a077aefc8ec970fd0
Last active January 23, 2019 07:09
Show date as: Published on {date} at {time} | Updated on {date} at {time}
add_filter( 'generate_post_date_output', 'tu_show_modified_date' );
function tu_show_modified_date() {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = 'Updated on: <time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
@them-es
them-es / functions.php
Last active November 22, 2020 05:17
Ninja Forms: Server side spam protection using WordPress comment blacklist keys
<?php
/**
* [Update] This Gist has been integrated into the WordPress Plugin "I don't like Spam!" which supports more WordPress Contact Forms:
* https://wordpress.org/plugins/i-dont-like-spam
*
* Ninja Forms: Server side spam protection making use of the WordPress Comment Blocklist
* https://developer.ninjaforms.com/codex/custom-server-side-validation
*
* Enter your blocklist here: Settings > Discussion > Comment Blocklist
* https://developer.wordpress.org/reference/functions/wp_blacklist_check
@andreasnrb
andreasnrb / uk-vat-id-validation.php
Last active January 22, 2021 01:10
Code snippet to validate UK VAT IDs with Barns2uks EDD EU VAT plugin. Requires https://vatsense.com API KEY
<?php
//License is public domain, use to your hearts content. I take no ownership or responsibility
use Barn2\Plugin\EDD_VAT\VAT_Check_Result;
add_filter( 'edd_vat_number_check', function ($result, $vat_number, $country_code ) {
if($result->error === VAT_Check_Result::INVALID_INPUT && $country_code==='GB') {
if(strlen($vat_number)!==9 || !filter_var($vat_number, FILTER_VALIDATE_INT)) {
return $result;
}
@brianleejackson
brianleejackson / gp-read-more.php
Last active July 13, 2022 21:34
GeneratePress read more link on blog post archive, as seen on https://woorkup.com
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;
$settings = wp_parse_args(
get_option( 'generate_blog_settings', array() ),
generate_blog_get_defaults()
);
if ( has_excerpt() ) {
$output = sprintf('%1$s <br /><a class="read-more" href="%2$s">%3$s →</a>',
@pradeepdotco
pradeepdotco / rssfeedimage.php
Created October 3, 2015 10:54
Function to add featured image to RSS feed
<?php
add_filter( 'the_content', 'featured_image_in_feed' );
function featured_image_in_feed( $content ) {
global $post;
if( is_feed() ) {
if ( has_post_thumbnail( $post->ID ) ){
$output = get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'float:right; margin:0 0 10px 10px;' ) );
$content = $output . $content;
}
}
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active March 28, 2024 01:45
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {