Skip to content

Instantly share code, notes, and snippets.

@kevinlisota
kevinlisota / default.conf
Created April 16, 2018 04:29
nginx catch-all server block
# Catch-all server block, resulting in a 444 response for unknown domains.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 444;
}
@kevinlisota
kevinlisota / template.json
Created April 27, 2017 21:01
ACS ARM template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"masterDnsNamePrefix": {
"type": "string",
"metadata": {
"description": "Sets the Domain name prefix for the Master nodes in a cluster. The concatenation of the domain name and the regionalized DNS zone make up the fully qualified domain name associated with the public IP address."
}
},
@kevinlisota
kevinlisota / photon-images.php
Last active August 29, 2015 14:22
Call Jetpack_PostImages to resize thumbnails via Photon
<a href="<?php echo get_the_permalink(); ?>">
<?php
//check if Jetpack is acctive
if (class_exists('Jetpack_PostImages')) {
//get the ID of the post thumbnail image
$thumb_id = get_post_thumbnail_id();
//get the URL of the image
$img_url = wp_get_attachment_image_src($thumb_id, 'full');
//get the image alt text
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
@kevinlisota
kevinlisota / google-analytics-view-source
Last active August 29, 2015 14:21
Confirm your Google Analytics snippet for author tracking in WordPress
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'YOUR ANALYTICS ID HERE', 'auto');
ga('set', 'dimension1', 'John Q. Author');
ga('send', 'pageview');
</script>
@kevinlisota
kevinlisota / omit-twitter-script-oembed.php
Created April 28, 2015 03:02
Omit Twitter widgets.js script in HTML returned from oEmbed endpoint in WordPress
<?php
function omit_twitter_script($provider, $url, $args) {
//get the hostname of the oEmbed endpoint provider being called
$host = parse_url($provider, PHP_URL_HOST);
//check to see that hostname is twitter.com
if (strpos($host, 'twitter.com') !== false) {
//adding ?omit_script=true to oEmbed endpoint call stops the returned HTML from containing widgets.js
$provider = add_query_arg('omit_script', 'true', $provider);
}
//return the $provider URL so the oEmbed can be fetched
@kevinlisota
kevinlisota / google-analytics-author-tracking.php
Last active October 18, 2018 11:49
add WordPress author tracking using Google Analytics custom dimension
//Google Universal Analytics
function google_analytics() { ?>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'YOUR ANALYTICS PROPERTY ID HERE', 'auto');
<?php if (is_singular('post') :
@kevinlisota
kevinlisota / logo-redirect.js
Created February 6, 2015 04:03
Right-click on navbar logo redirect to logos page
// navbar logo redirect
document.addEventListener("contextmenu", function(e) {
var triggerClass = "right-click-redirect",
logosUrl = "/logos/",
$target = $(e.target);
if ($target.hasClass(triggerClass) || $target.parents('.' + triggerClass).length) {
if (window.location.pathname !== logosUrl) {
window.location = logosUrl;
} else {
alert("You can download our logo below");
@kevinlisota
kevinlisota / remove_default_category.php
Last active May 4, 2017 05:53
Remove default WordPress category at time of publishing when another category is present
//remove default category (uncategorized) when another category has been set
function remove_default_category($ID, $post) {
//get all categories for the post
$categories = wp_get_object_terms($ID, 'category');
//if there is more than one category set, check to see if one of them is the default
if (count($categories) > 1) {
foreach ($categories as $key => $category) {
//if category is the default, then remove it
@kevinlisota
kevinlisota / exclude_posts_search_results.php
Last active February 5, 2021 20:35
Excluding certain posts from WordPress search results based on custom field values
function exclude_nonadvertorial_search($query) {
//only run for the main query and don't run on admin pages
if (!is_admin() && $query->is_main_query()) {
//now check to see if you are on a search results page
if ($query->is_search) {
//get sponsor posts that are NOT advertorials, so we can exclude their IDs from search
$args = array(
//get posts of the custom post type sponsor_post
'post_type' => 'sponsor_post',
//get all posts