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 / 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 / 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
@FreshLondon
FreshLondon / hexdec-to-rgba-usage.php
Created August 16, 2019 11:24
Convert hexdec color string to rgb(a) string > USAGE
<?
// Here's a usage example how to use this function for dynamicaly created CSS
$color = '#ffa226';
$rgb = hex2rgba($color);
$rgba = hex2rgba($color, 0.7);
// CSS output
echo '
@FreshLondon
FreshLondon / functions-edit.php
Created August 12, 2020 18:36
Only load WooCommerce scripts on shop pages/checkout/cart
if (!is_woocommerce() && !is_cart() && !is_checkout()) {
remove_action('wp_enqueue_scripts', [WC_Frontend_Scripts::class, 'load_scripts']);
remove_action('wp_print_scripts', [WC_Frontend_Scripts::class, 'localize_printed_scripts'], 5);
remove_action('wp_print_footer_scripts', [WC_Frontend_Scripts::class, 'localize_printed_scripts'], 5);
}