Skip to content

Instantly share code, notes, and snippets.

View elliottmangham's full-sized avatar
🤓

Elliott Mangham elliottmangham

🤓
View GitHub Profile
@elliottmangham
elliottmangham / get_partial.php
Last active December 3, 2020 17:06
php / utilities
/************************************
* Include partial file.
* @param string $sFilePath The component to include
* @param array $aScopeVariables An array of variables to make available in the component
* @param boolean $bReturn Return the markup instead off outputting it?
************************************/
function get_partial( $sFilePath, $aScopeVariables = [], $bReturn = false ) {
ob_start();
@elliottmangham
elliottmangham / get_component.php
Last active December 3, 2020 18:59
WordPress (PHP) / Utilities
/************************************
* Include component file.
* @param string $sFilePath The component to include
* @param array $aScopeVariables An array of variables to make available in the component
* @param boolean $bReturn Return the markup instead off outputting it?
************************************/
function get_component( $sFilePath, $aScopeVariables = [], $bReturn = false ) {
ob_start();
@elliottmangham
elliottmangham / get_builder.php
Last active December 3, 2020 19:00
WordPress (PHP) / Utilities / Get flexible content builder
/***************
* Includes the page builder file
* @param string $sFilePath The builder to include
* @param string $sFieldName ACF field name
* @param array $aScopeVariables An array of variables to make available in the component
***************/
function get_builder( $sFilePath, $sFieldName = 'blocks', $aScopeVariables = [] ) {
ob_start();
@elliottmangham
elliottmangham / get_svg.php
Last active December 3, 2020 19:01
WordPress (PHP) / Utilities / Serve inline SVG
/************************************
* Include SVG file.
* @param string $sFilePath The path of the SVG file
* @param boolean $bReturn Return the output instead of echoing (optional)
************************************/
function get_svg( $sFilePath = NULL, $bReturn = false ) {
$sFileContents = NULL;
$sSvgPath = THEME_DIR_FILEPATH . '/media/dist/img/' . $sFilePath . '.svg';
@elliottmangham
elliottmangham / get_imgix.php
Last active December 4, 2020 14:07
WordPress (PHP) / Utilities / Serve Imgix as a <img> or <picture> tag
/************************************
* Include Imgix image
* @param array $aImageScope The image settings
* @param array $aClasses Apply classes to the image (optional)
* Sandbox: https://sandbox.imgix.com/
* API Reference: https://docs.imgix.com/apis/rendering
* Notes:
- Do not include `dpr` param in `settings`, instead set a maximum DPR support in `max_dpr` parameter.
@elliottmangham
elliottmangham / LocomotiveScroll_onCall.js
Last active December 7, 2020 08:16
JS / LocomotiveScroll / Helpers
scroll.on( 'call', ( value ) => {
if ( value === 'exampleNameOne' ) {
console.log( 'Example #1' );
}
if ( value === 'exampleNameTwo' ) {
console.log( 'Example #1' );
}
@elliottmangham
elliottmangham / fnShowBrowserVersion.js
Created December 7, 2020 08:36
JS / Utilities / Browser detection and output
/**************************************************************
* Browser detection and output
**************************************************************/
function fnShowBrowserVersion() {
var sDomainName = window.location.hostname;
// Restrict to non-production sites
if ( sDomainName.search( ".local" ) >= 1 || sDomainName.search( ".flywheelsites" ) >= 1 ) {
@elliottmangham
elliottmangham / fnScrollToID.js
Created December 7, 2020 08:37
JS / Utilities / Scroll to hash
/**************************************************************
* Scroll to ID (hash links)
**************************************************************/
function fnScrollToID( oEvent ) {
// Prevent default anchor behaviour
oEvent.preventDefault();
// Get offset value (optional)
@elliottmangham
elliottmangham / DetectMouswheel.js
Created December 7, 2020 08:40
JS / Utilities / Detect mousewheel scroll
$( 'body' ).bind( 'mousewheel', function( e ) {
if ( e.originalEvent.wheelDelta / 120 > 0 ) {
console.log( 'Scrolling up' );
}
else {
console.log( 'Scrolling down' );
}
} );
@elliottmangham
elliottmangham / .htaccess
Created December 7, 2020 08:46
Apache / Password-protect directory
# ----------------------------------------------------------------------
# Password protect
# ----------------------------------------------------------------------
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /dir/to/root/.htpasswd
Require valid-user