Skip to content

Instantly share code, notes, and snippets.

@tomkao
tomkao / htaccess
Last active November 2, 2019 01:37
Far future Expires header
# BEGIN HTML5 Boilerplate
###
### This contains the HTML5 Boilerplate .htaccess that can be found at:
### github.com/h5bp/html5-boilerplate/blob/master/.htaccess
###
### Added:
### Block access to access to WordPress files that reveal version information.
###
### Commented out by default:
@gerbenvandijk
gerbenvandijk / Mark parent navigation active when on custom post type single page
Last active July 16, 2024 16:53
Mark (highlight) custom post type parent as active item in Wordpress Navigation.When you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.
<?php
function add_current_nav_class($classes, $item) {
// Getting the current post details
global $post;
// Get post ID, if nothing found set to NULL
$id = ( isset( $post->ID ) ? get_the_ID() : NULL );
@westonruter
westonruter / filter-post-thumbnail-id.php
Last active January 5, 2023 06:42
How to filter the response for get_post_thumbnail_id()
<?php
/**
* How to filter the value that would be returned by get_post_thumbnail_id()
*/
add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) {
// We want to pass the actual _thumbnail_id into the filter, so requires recursion
static $is_recursing = false;
// Only filter if we're not recursing and if it is a post thumbnail ID
@cferdinandi
cferdinandi / stop-video.js
Last active July 19, 2024 23:33
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
/**
* Stop an iframe or HTML5 <video> from playing
* @param {Element} element The element that contains the video
*/
var stopVideo = function ( element ) {
var iframe = element.querySelector( 'iframe');
var video = element.querySelector( 'video' );
if ( iframe ) {
var iframeSrc = iframe.src;
iframe.src = iframeSrc;
<?php
/**
* Join a string with a natural language conjunction at the end.
*/
function natural_language_join(array $list, $conjunction = 'and') {
$last = array_pop($list);
if ($list) {
return implode(', ', $list) . ' ' . $conjunction . ' ' . $last;
}
return $last;
@theeventscalendar
theeventscalendar / exclude events category.php
Last active November 27, 2022 03:30 — forked from elimn/tribe_exclude_events_category.php
Excludes specified categories from List and Month views. Add you own categories in line 9.
<?php
/*
* Removes categories "meetup" and "shindig" from list and month views
*/
function tribe_exclude_events_category( $wp_query ) {
// Slugs for the categories you wish to hide
$exclude_cats = array('meetup', 'shindig');
@wizioo
wizioo / gitignore_per_git_branch.md
Last active July 22, 2024 00:18
HowTo have specific .gitignore for each git branch

How to have specific .gitignore for each git branch

Objective

My objective is to have some production files ignored on specific branches. Git doesn't allow to do it.

Solution

My solution is to make a general .gitignore file and add .gitignore.branch_name files for the branches I want to add specific file exclusion. I'll use post-checkout hook to copy those .gitignore.branch_name in place of .git/info/exclude each time I go to the branch with git checkout branch_name.

@jo-flynn
jo-flynn / functions.php
Created September 8, 2016 20:45
silencio_partial
<?php
/**
* Load a template part & pass in variables declared in caller scope. Optionally return as a string.
* @param string $path path to template file, minus .php (eg. `content-page`, `partial/folder/template-name`)
* @param array $args map of variables to load into scope
* @param bool $echo echo or return rendered template
* @return null or rendered template string
*/
function silencio_partial($path, $args = [], $echo = true) {
if (!empty($args)) {
@mgibbs189
mgibbs189 / custom-loop.php
Last active September 1, 2022 13:25 — forked from SauntValerian/gist:a79845e301de969017e714a96ffee6da
Multiple Loops for FacetWP
<?php
$args = array(
'post_type' => 'location',
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'title',
'facetwp' => true,
'tax_query' => array(
array(
'taxonomy' => 'advertiser-level',
@alex-boom
alex-boom / Mixin-rem-calc.scss
Last active June 14, 2021 15:08
Mixin-rem-calc
/// Mixin rem-calc for converting px units into rem units
/// @example scss - Usage
/// .element {
/// font-size: rem-calc(20);
/// }
///
/// @example css - CSS Output
/// .element {
/// font-size: 1.25rem;
/// }