Skip to content

Instantly share code, notes, and snippets.

Avatar
✍️
Writing

Brian Jackson brianleejackson

✍️
Writing
View GitHub Profile
@andreasnrb
andreasnrb / uk-vat-id-validation.php
Last active Jan 22, 2021
Code snippet to validate UK VAT IDs with Barns2uks EDD EU VAT plugin. Requires https://vatsense.com API KEY
View uk-vat-id-validation.php
<?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;
}
@them-es
them-es / functions.php
Last active Nov 22, 2020
Ninja Forms: Server side spam protection using WordPress comment blacklist keys
View functions.php
<?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
View minimal-analytics-snippet.js
(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 = () => {
View gp-disable-google-fonts.php
add_action( 'wp_enqueue_scripts','tu_remove_google_fonts', 10 );
function tu_remove_google_fonts() {
wp_dequeue_style( 'generate-fonts' );
}
View gp-yoast-seo-cdn.php
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' );
@brianleejackson
brianleejackson / gp-read-more.php
Last active Jul 13, 2022
GeneratePress read more link on blog post archive, as seen on https://woorkup.com
View gp-read-more.php
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>',
@generatepress
generatepress / gist:8bc94ae43f67c40a077aefc8ec970fd0
Last active Jan 23, 2019
Show date as: Published on {date} at {time} | Updated on {date} at {time}
View gist:8bc94ae43f67c40a077aefc8ec970fd0
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' ) ),
@pradeepdotco
pradeepdotco / rssfeedimage.php
Created Oct 3, 2015
Function to add featured image to RSS feed
View rssfeedimage.php
<?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;
}
}