Skip to content

Instantly share code, notes, and snippets.

View davidwebca's full-sized avatar

David Lapointe Gilbert davidwebca

View GitHub Profile
@davidwebca
davidwebca / wp-global-post-count.php
Last active April 24, 2022 16:13
Global current_post counter, WP_Query agnostic
<?php
/**
* Create a globally accessible counter for all queries
* Even custom new WP_Query! Include inside functions.php in your theme.
* This allows you to have a post counter available in your sub-templates
* accessible even if you use get_template_part();
*
* Example
*
* global $current_loop_post_index;
@davidwebca
davidwebca / override-wp-core-blocks-sage-10.php
Last active March 6, 2023 20:40
Add blade / override core block views in Sage 10.
<?php
/**
* Add this to your filters.php file in a Sage 10 theme.
* It will look at "resources/views/core/{blockname}.blade.php
* and render the view with "block_content" and "block" as variables.
*
* You can also use View Composers built in Sage 10 to pass more
* data to the block as you wish. For ACF blocks, I recommend
* generoi/sage-acfblocks which is definitely the cleanest
* method to include ACF blocks in Sage 10 I found so far.
@davidwebca
davidwebca / gist:e26186b8f4c6795b19c043fffb6f9861
Last active December 18, 2023 15:29
Detect black screen and split with ffmpeg remux
# Splits video to separate scenes files when full black frames are found in the video
# Inspired by https://gist.github.com/achesco/4dc2ebf13378a0a61fc26c7fe01f539e
# Who got inspired by https://stackoverflow.com/a/38205105
#!/bin/bash
file=""
out="./"
dur=0.05
stripaudio=""
@davidwebca
davidwebca / svg-functions.php
Last active January 26, 2021 19:50 — forked from kingkool68/svg-functions.php
SVG helper functions for WordPress
<?php
/**
* Include inline svg with + allow custom attributes as php function arguments
*
* Based on
* https://gist.github.com/kingkool68/6d72977fe8c82eeb9a85295ac3623cde#file-svg-functions-php
*
*/
/**
@davidwebca
davidwebca / custom-wp-nav-menu-classes.php
Last active February 11, 2024 01:35
Allow adding custom classes to WordPress menu ul, li, a and at different depths. Perfect for TailwindCSS and AlpineJS usage.
<?php
/**
* WordPress filters to allow custom arguments to wp_nav_menu to,
* in turn, allow custom classes to every element of a menu.
*
* You can apply a class only to certain depth of your menu as well.
*
* The filters use the depth argument given by WordPress
* which is an index, thus starts with level 0 (zero).
*
@davidwebca
davidwebca / pllstrings.php
Created June 1, 2021 13:46
Translate regular gettext and underscore functions with Polylang's strings
<?php
add_filter('gettext', function($translation, $text, $domain) {
if(is_admin()) {
return $translation;
}
if($domain == 'mythemedomain') {
if(function_exists('icl_register_string')){
$slug = sanitize_title($text);
icl_register_string($domain, $slug, $text);
@davidwebca
davidwebca / tailwind-jit-dynamic-scoping.md
Last active December 9, 2021 05:15
Tailwind JIT Dynamic Scoping

Tailwind Dynamic Scoping

This is a quick and dirty simple method to allow dynamic scoping in Tailwind CSS. It happens on-the-fly thanks to the JIT engine and doesn't need any new config when you want to add a new scope.

Generate this

.admin .scope-\[\.admin\|bg-red-500\+underline\] {
  --tw-bg-opacity: 1;
 background-color: rgb(239 68 68 / var(--tw-bg-opacity));
@davidwebca
davidwebca / block-style-locations.php
Last active December 21, 2021 00:38
Block style locations for ACF
<?php
/**
THIS IS NOW A FULL GITHUB REPO: https://github.com/davidwebca/acf-block-style-location
*/
add_filter('acf/location/rule_values/acf_block_style', function ($choices) {
@davidwebca
davidwebca / post-ftp-push
Last active December 11, 2023 16:01
git-ftp rsync hook
#!/bin/bash
remote="$1"
originalurl="$2"
# I created this bash script to hook with git-ftp since the .git-ftp-include mecanism
# doesn't remove files on the remote host which often leads to undesired results.
#
# The script needs a .git-ftp-rsync file at the root of your git repo and a simple
# line-by-line list of folders you want to sync. The .git-ftp-rsync file is a very
# rudimentary one and does not understand the standard .gitignore syntaxes.
@davidwebca
davidwebca / lazyblock-tailwind-cache.php
Last active June 24, 2022 00:09
Create tmp files for Lazy Block to allow Tailwind CSS to watch for CSS class names and create / purge properly
<?php
/**
* Allows HTML + Handlebars or database-saved PHP code to be
* cached into files so that Tailwind CSS can detect and watch
* for classes used and purge unecessary ones.
*
* @see https://github.com/nk-crew/lazy-blocks/
* @see https://github.com/nk-crew/lazy-blocks/issues/246
*/