Skip to content

Instantly share code, notes, and snippets.

View yanknudtskov's full-sized avatar

Yan Knudtskov yanknudtskov

View GitHub Profile
@yanknudtskov
yanknudtskov / search-by-algolia-for-woocommerce.php
Created August 22, 2019 13:51 — forked from rayrutjes/search-by-algolia-for-woocommerce.php
This is a boilerplate for using Algolia in WooCommerce
<?php
/**
* @wordpress-plugin
* Plugin Name: Search by Algolia for WooCommerce - Instant & Relevant results
*/
/**
* If Algolia is not active, let users know.
@yanknudtskov
yanknudtskov / archive.php
Last active February 7, 2019 12:44 — forked from billerickson/archive.php
Removing advanced custom fields from the frontend
<?php
/**
* Category Subtitle
*
*/
function be_category_subtitle() {
// Make sure this is a category archive
if( ! is_category() )
@yanknudtskov
yanknudtskov / functions.php
Last active February 7, 2019 12:44 — forked from billerickson/functions.php
Removing advanced custom fields from the frontend
<?php
function be_call_to_action() {
$title = esc_html( get_option( 'options_be_cta_title' ) );
$button_text = esc_html( get_option( 'options_be_cta_button_text' ) );
$button_url = esc_url( get_option( 'options_be_cta_button_url' ) );
if( $title && $button_text && $button_url )
echo '<div class="call-to-action"><div class="wrap"><p>' . $title . '</p><p><a href="' . $button_url . '" class="button">' . $button_text . '</a></p></div></div>';
@yanknudtskov
yanknudtskov / template-landing.php
Last active February 9, 2019 23:38 — forked from billerickson/template-landing.php
Removing advanced custom fields from the frontend
<?php
/**
* Your Child Theme
*
* Template Name: Landing
*/
/**
* Flexible Content
*
@yanknudtskov
yanknudtskov / functions.php
Last active February 7, 2019 12:44 — forked from billerickson/functions.php
Removing advanced custom fields from the frontend
<?php
$videos = get_post_meta( get_the_ID(), 'be_attorney_video', true );
if( $videos ) {
for( $i = 0; $i < $videos; $i++ ) {
$title = esc_html( get_post_meta( get_the_ID(), 'be_attorney_video_' . $i . '_title', true ) );
$video = esc_url( get_post_meta( get_the_ID(), 'be_attorney_video_' . $i . '_video', true ) );
$thumbnail = (int) get_post_meta( get_the_ID(), 'be_attorney_video_' . $i . '_thumbnail', true );
// Thumbnail field returns image ID, so grab image. If none provided, use default image
@yanknudtskov
yanknudtskov / wp-42573.php
Created November 27, 2017 16:35 — forked from westonruter/wp-42573.php
WP Trac #42573: Fix for theme template caching. https://core.trac.wordpress.org/ticket/42573
<?php
/**
* Plugin name: WP Trac #42573: Fix for theme template file caching.
* Description: Flush the theme file cache each time the admin screens are loaded which uses the file list.
* Plugin URI: https://core.trac.wordpress.org/ticket/42573
* Author: Weston Ruter, XWP.
* Author URI: https://weston.ruter.net
*/
function wp_42573_fix_template_caching( WP_Screen $current_screen ) {
@yanknudtskov
yanknudtskov / js_google_fonts_async_ieshim
Created August 5, 2016 21:12 — forked from kosmiq/js_google_fonts_async_ieshim
An updated version of Thomas Bensmanns Load Google Fonts via JS (https://bensmann.no/google-webfonts-performance/) with a SHIM for IE9 and IE8.
WebFontConfig = {
google: { families: [ \'Ek+Mukta:200,800:latin\' ] }
};
var cb = function() {
var wf = document.createElement(\'script\');
wf.src = \'//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';
wf.type = \'text/javascript\';
wf.async = \'true\';
var s = document.getElementsByTagName(\'script\')[0];
s.parentNode.insertBefore(wf, s);
@yanknudtskov
yanknudtskov / add-to-cart.php
Created August 1, 2016 00:51 — forked from lukecav/add-to-cart.php
Display Product Variations in the Shop Loop
<?php
/**
* Loop Add to Cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/loop/add-to-cart.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@yanknudtskov
yanknudtskov / plugin.php
Created February 12, 2016 10:07 — forked from mathetos/plugin.php
Dependent Plugin Activation/Deactivation and Alert
<?php
/*
* Dependent Plugin Activation/Deactivation
*
* Sources:
* 1. https://pippinsplugins.com/checking-dependent-plugin-active/
* 2. http://10up.com/blog/2012/wordpress-plug-in-self-deactivation/
*
*/
<?php
function my_is_valid_domain( $url ) {
$whitelisted_domains = array( 'mydomain.com', 'mydomain.net' );
$domain = parse_url( $url, PHP_URL_HOST );
// Check if we match the domain exactly
if ( in_array( $domain, $whitelisted_domains ) )
return true;
$valid = false;