Skip to content

Instantly share code, notes, and snippets.

/**
* Filter taxonomy terms by term_order if term_order is specified
*
* @param string $orderby Method to order terms by
* @param array $query_vars The query
* @param array $taxonomies Array of taxonomies
*/
function filter_terms_order( $orderby, $query_vars, $taxonomies ) {
return 'term_order' === $query_vars['orderby'] ? 'term_order' : $orderby;
}
@rossberenson
rossberenson / functions.php
Last active March 26, 2020 18:47 — forked from jo-flynn/functions.php
Get Template Part With Arguments ( Forked incase if author removes it )
<?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 rb_get_template_part($path, $args = [], $echo = true) {
if (!empty($args)) {
@rossberenson
rossberenson / _mixin-what-input.scss
Last active May 16, 2020 22:27
SCSS Mixin to use with What-Input
/**
* Mixin for What-Input
* https://github.com/ten1seven/what-input
*
* Example use:
* .element {
* @include what-input(keyboard) {
* outline: 1px dotted black;
* }
*/
/**
* Removes empty paragraph tags from shortcodes in WordPress.
*
* https://thomasgriffin.com/how-to-remove-empty-paragraph-tags-from-shortcodes-in-wordpress/
*/
function remove_empty_paragraph_tags_from_shortcodes_wordpress( $content ) {
$to_fix = array(
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
@rossberenson
rossberenson / isMotionOk.js
Created March 2, 2023 19:51
Check to see if motion is ok
/**
* Is motion ok?
*
* Prevent animations from running if the user has enabled 'reduce motion' on their machines.
*
* Use as a conditional. if ( isMotionOk ) { runAnimation(); }
*/
function checkMQ( mediaQuery ) {
return ! mediaQuery.matches;
@rossberenson
rossberenson / webpack.config.js
Created July 8, 2023 02:35 — forked from bahiirwa/webpack.config.js
Multiple entry points for webpack.config.js using @wordpress/scripts
// Set from https://www.npmjs.com/package/@wordpress/scripts
// Add package.json with the @wordpress/scripts dependency.
// Add a root file called webpack.config.js
// Import the original config from the @wordpress/scripts package.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
// Import the helper to find and generate the entry points in the src directory
const { getWebpackEntryPoints } = require( '@wordpress/scripts/utils/config' );
@rossberenson
rossberenson / functions.php
Created March 26, 2024 21:30 — forked from simplistik/functions.php
Fetch WP "posts" in chunks.
<?php
/**
* Fetch posts in chunks.
*
* This function fetches posts in chunks of a specified size, which can be useful for large datasets.
*
* @param string $post_type The type of post to fetch. Default is 'post'.
* @param int $posts_per_page The number of posts to fetch per page. Default is 100.
* @param array $custom_args Custom arguments to pass to WP_Query. Default is an empty array.
*