Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex FreshLondon

  • FreshLondon
View GitHub Profile
View check-odd-even-foreach.php
<?
// I'd like to see whether the task row is odd or even in CSS for printing
// as for PHP DomPDF I cant use pseudo classes (:nth-child(odd))
// get the tasks
$tasks = json_decode(get_post_meta($post->ID, 'tasks', true), true);
// set an evenm starting point, eg 0
$row_oddEven = 10;
View check-odd-even.php
<?php
// Check whether a number is odd or even.
if (!function_exists('checkOddEven')) {
function checkOddEven($number){
if($number % 2 == 0){
echo "Even";
}
else{
echo "Odd";
}
@FreshLondon
FreshLondon / functions-edit.php
Created Aug 12, 2020
Only load WooCommerce scripts on shop pages/checkout/cart
View functions-edit.php
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);
}
@FreshLondon
FreshLondon / hexdec-to-rgba-usage.php
Created Aug 16, 2019
Convert hexdec color string to rgb(a) string > USAGE
View hexdec-to-rgba-usage.php
<?
// 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 / hexdec-to-rgba.php
Last active Aug 16, 2019
Convert hexdec color string to rgb(a) string
View hexdec-to-rgba.php
<?
/* 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
View mahonefirm-form.scss
.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 / excerpt-from-acf-field.php
Created Apr 25, 2019
Create excerpt from ACF field
View excerpt-from-acf-field.php
<?
// 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 / fading-hyperlink.js
Created Apr 12, 2019
Fading screen on hyperlink click
View fading-hyperlink.js
@FreshLondon
FreshLondon / format-phone-number.php
Created Apr 11, 2019
Format ACF phone number in a text field
View format-phone-number.php
<?
/*
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
View debugging-array.php
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
You can’t perform that action at this time.