Skip to content

Instantly share code, notes, and snippets.

@FreshLondon
FreshLondon / display-all-image-sizes.php
Created March 5, 2019 01:33
Display all available image sizes in WordPress
<?
function _get_all_image_sizes() {
global $_wp_additional_image_sizes;
$default_image_sizes = get_intermediate_image_sizes();
foreach ( $default_image_sizes as $size ) {
$image_sizes[ $size ][ 'width' ] = intval( get_option( "{$size}_size_w" ) );
$image_sizes[ $size ][ 'height' ] = intval( get_option( "{$size}_size_h" ) );
$image_sizes[ $size ][ 'crop' ] = get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false;
@FreshLondon
FreshLondon / strip-acf-meta-from-search.php
Created March 5, 2019 18:18
Strips posts from search queries if ACF meta value post_is_hidden is active
<?
/**
* Strips posts from search queries if ACF meta value post_is_hidden is active.
*
* @author AM.HIGH
* @version 1.0.0
* @since 1.0.0
*/
function dontSearchTheHidden($query) {
@FreshLondon
FreshLondon / _media_query_mixins.scss
Created March 13, 2019 06:43
Sass (SCSS) media query mixins
//
// MEDIA QUERIES
//––––––––––––––––––––––––––––––––––––––––––––––––––
// A map of breakpoints.
$breakpoints: (
xs: 576px,
sm: 768px,
md: 992px,
lg: 1200px
@FreshLondon
FreshLondon / metres-to-feet-and-inches.php
Last active March 16, 2019 06:31
Function: metres to feet and inches
<? function metersToFeetInches($meters, $echo = true) {
$m = $meters;
$valInFeet = $m * 3.2808399;
$valFeet = (int)$valInFeet;
$valInches = round(($valInFeet - $valFeet) * 12);
$data = $valFeet."&prime;".$valInches."&Prime;";
if ($echo == true) {
echo $data;
} else {
return $data;
@FreshLondon
FreshLondon / debugging-array.php
Created March 17, 2019 12:06
Array debugging
Array
(
[0] => Array
(
[ID] => 840
[id] => 840
[title] => creativebacon
[filename] => creativebacon.jpg
[filesize] => 67847
[url] => http://localhost:8888/FreshLondon/wp-content/uploads/2016/01/creativebacon.jpg
@FreshLondon
FreshLondon / format-phone-number.php
Created April 11, 2019 14:08
Format ACF phone number in a text field
<?
/*
In this example our ACF field is 'footer_phone_number'
*
$original = '+44 (0)1234 567 890';
$original = '0044 01234 567 890';
$original = '01234 567 890';
$original = '44 1234 567 890';
Result should always be:
'+441234567890
@FreshLondon
FreshLondon / fading-hyperlink.js
Last active February 18, 2021 17:48
Fading screen on hyperlink click
@FreshLondon
FreshLondon / excerpt-from-acf-field.php
Created April 25, 2019 09:37
Create excerpt from ACF field
<?
// lets assume the ACF field we want to create an excerpt for is called 'content'
$raw_content = get_field('content');
$trimmed_content = wp_trim_words($raw_content);
$clean_excerpt = apply_filters('the_excerpt', $trimmed_content);
echo $clean_excerpt;
?>
@FreshLondon
FreshLondon / mahonefirm-form.scss
Created May 16, 2019 08:23
MahoneFirmFormScss
.contact-outer {
.contact-halves {
display: flex;
justify-content: space-between;
@media (max-width: 767px) {
flex-direction: column;
}
.contact-left {
display: flex;
flex-direction: column;
@FreshLondon
FreshLondon / hexdec-to-rgba.php
Last active August 16, 2019 11:23
Convert hexdec color string to rgb(a) string
<?
/* Convert hexdec color string to rgb(a) string */
function hex2rgba($color, $opacity = false) {
$default = 'rgb(0,0,0)';
//Return default if no color provided
if (empty($color)) return $default;
//Sanitize $color if "#" is provided