Skip to content

Instantly share code, notes, and snippets.

View thetwopct's full-sized avatar

James Hunt thetwopct

View GitHub Profile
@thetwopct
thetwopct / share.php
Last active January 21, 2019 09:29
Quick and dirty PHP share
<?php
$name = "Company Name"; // can include @handle here too
$title = "My amazing page";
// gets current domain and page
$currentDomain = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
// creates the share links
$twitterURL = 'https://twitter.com/intent/tweet?text='.$title.'&amp;url='.$currentDomain.'&amp;via='.$name;
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$currentDomain;
?>
@thetwopct
thetwopct / functions.php
Created March 4, 2019 09:02
Add javascript file per page for WordPress
function load_js_assets() {
if( is_page( ID ) ) {
wp_enqueue_script('my-js', 'PATH TO JS FILE', array('jquery'), '', false);
}
}
add_action('wp_enqueue_scripts', 'load_js_assets');
@thetwopct
thetwopct / style.css
Last active June 21, 2019 06:06
CSS Full Cover Background Images
/* becuase I always forget */
/* becuase I always forget */
body {
background-image: url('https://via.placeholder.com/250x200/d9d9d9/000000');
background-position: center center;
background-repeat: no-repeat;
// background-attachment: fixed; // remove to be fixed
background-size: cover;
@thetwopct
thetwopct / fullpage.js
Created March 13, 2019 06:01
Hide Up/Down Navigation Arrows on First and Last slides on fullpage.js
new fullpage("#fullpage", {
navigation: false,
controlArrows: false,
afterLoad: function(origin, destination, direction) {
var loadedSection = this;
if (destination.isFirst) {
$("#moveUp").hide();
} else {
$("#moveUp").fadeIn();
}
@thetwopct
thetwopct / .htaccess
Created April 9, 2019 13:05
Redirect images to production server
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$
RewriteRule ^(.*)$ https://productionsite.com/$1 [QSA,L]
@thetwopct
thetwopct / base.scss
Created April 16, 2019 04:59
Reference SCSS Variable in SCSS Calc
$body_padding: 1em;
body {
height: calc(100% - #{$body_padding})
}
// #{$variable}
@thetwopct
thetwopct / _style.scss
Created April 21, 2019 06:17
Custom woocommerce-product-gallery__trigger (zoom lightbox icon)
// add text before
.woocommerce-product-gallery__trigger:before {
content: "Click to zoom ";
// set both font sizes
font-size: 13px;
font-size: 0.815rem;
letter-spacing: normal;
color: red;
font-weight: 500;
}
@thetwopct
thetwopct / page.php
Last active April 23, 2019 10:17
ACF Responsive Images (srcset)
<?php
$img = the_sub_field( 'image' ); // or get_field ACF - make sure field is set to ID
$size = 'home-hero'; // thumbnail size
$src = wp_get_attachment_image_src( $img, $size );
$srcset = wp_get_attachment_image_srcset( $img, $size );
?>
<img class="pillar-image"
src="<?php echo esc_url( $src[0] ); ?>"
srcset="<?php echo esc_attr( $srcset ); ?>"
@thetwopct
thetwopct / functions.php
Created May 9, 2019 17:12
Custom Orderby
function theme_modify_the_main_query( $query ) {
if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'price' ) {
// Modify the main query
if( ! is_admin() && $query->is_main_query() ) {
$args = array(
'relation' => 'AND',
'query_one' => array(
@thetwopct
thetwopct / style.css
Last active June 11, 2019 07:54
Highlight all items on page with CSS borders (debug)
* { outline: 2px dotted red }
* * { outline: 2px dotted green }
* * * { outline: 2px dotted orange }
* * * * { outline: 2px dotted blue }
* * * * * { outline: 1px solid red }
* * * * * * { outline: 1px solid green }
* * * * * * * { outline: 1px solid orange }
* * * * * * * * { outline: 1px solid blue }