Skip to content

Instantly share code, notes, and snippets.

@cfxd
cfxd / filter.php
Last active May 7, 2022 07:13
Efficient Responsive Images in WordPress. See https://cfxdesign.com/efficient-responsive-images-in-wordpress
<?php
/*
* THE FILTER
*
*/
function custom_responsive_image_sizes($sizes, $img_name, $attachment_id) {
$sizes = wp_get_attachment_image_sizes($attachment_id, 'original');
$meta = wp_get_attachment_metadata($attachment_id);
$width = $meta['width'];
<?php
if(!function_exists('wc_get_products')) {
return;
}
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$ordering = WC()->query->get_catalog_ordering_args();
$ordering['orderby'] = array_shift(explode(' ', $ordering['orderby']));
$ordering['orderby'] = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
@cfxd
cfxd / keybindings.json
Last active November 21, 2017 21:12
Visual Studio Code settings
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+1", "command": "" },
{ "key": "ctrl+2", "command": "" },
{ "key": "ctrl+3", "command": "" },
{ "key": "ctrl+4", "command": "" },
{ "key": "ctrl+5", "command": "" },
{ "key": "ctrl+6", "command": "" },
{ "key": "ctrl+7", "command": "" },
{ "key": "ctrl+8", "command": "" },
@cfxd
cfxd / add_initial_file_size_postmeta.php
Last active November 15, 2023 10:26
Create a sortable admin column for attachment (Media Library) file size. See https://cfxdesign.com/display-file-size-as-a-sortable-column-in-the-media-library/
<?php
// Adds initial meta to each attachment
function add_initial_file_size_postmeta($column_name, $post_id) {
static $query_ran;
if($query_ran !== null) {
$all_imgs = new WP_Query(array(
'post_type' => 'attachment',
'post_status' => 'inherit',
@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) {
.your-row-class > *:nth-child(3n+4) {
clear: left;
}
}
@cfxd
cfxd / .gitignore
Created February 22, 2016 16:31
GIT ignore for WP setup
**/node_modules
**/node_modules/**
.DS_Store
config.codekit
*.log
.htaccess
# Ignore everything in the root except the "wp-content" directory.
@cfxd
cfxd / package.json
Created February 22, 2016 16:26
Knight Digital package.json starter
{
"name": "knight_digital_starter",
"version": "1.0.0",
"author": "Knight Digital <info@knightdigital.se>",
"scripts": {
"autoprefixer": "postcss -u autoprefixer -r static/dist/css/*",
"scss": "node-sass --output-style compressed -o static/dist/css static/src/scss",
"lint": "eslint static/src/js",
"uglify": "mkdir -p static/dist/js && uglifyjs static/src/js/*.js -m -o static/dist/js/app.js && uglifyjs static/src/js/*.js -m -c -o static/dist/js/app.min.js",
"imagemin": "imagemin static/src/img static/dist/img -p",
--- wordpress-importer.php
+++ wordpress-importer_fix.php
@@ -63,7 +63,7 @@
var $url_remap = array();
var $featured_images = array();
- function WP_Import() { /* nothing */ }
+ public function __construct(){ /* nothing */ }
/**