Skip to content

Instantly share code, notes, and snippets.

View Web-Assembler's full-sized avatar

Anthony Vickery-Hartnell Web-Assembler

View GitHub Profile
@Web-Assembler
Web-Assembler / functions.php
Last active August 9, 2023 12:06
Add a custom body class based on the first Gutenberg block classes used.
<?php
add_filter( 'body_class', 'custom_body_classes' );
function custom_body_classes( $classes ) {
$post = get_post();
if ( ! is_null( $post ) ) {
if ( has_blocks( $post->post_content ) ) {
$blocks = parse_blocks( $post->post_content );
$first_block_attrs = $blocks[0]['attrs'];
$custom_classes = array();
@Web-Assembler
Web-Assembler / web-assembler-fdfp-tutorial.php
Last active August 7, 2023 13:28
Plugin for creating PDFs with FPDF
<?php
/*
* Plugin Name: Web Assembler - FPDF Tutorial
* Description: A plugin created to demonstrate how to build a PDF document from WordPress posts.
* Version: 0.1
* Author: Web Assembler
* Author URI: https://www.webassembler.co.uk/
*/
/**
@Web-Assembler
Web-Assembler / functions.php
Created January 17, 2023 16:22
Wordpress Edinburgh Meetup - Example actions and filters
<?php
/**
* Here is some custom code for the WordPress Edingburgh Hooks Talk titled
* "An introduction to WordPress Hooks". This demo uses the wordpress
* twentytwentythree theme.
*
* To use, drop this functions.php file within the theme.
*
* @package webassembler
@Web-Assembler
Web-Assembler / valetcreate.sh
Created December 8, 2022 19:39
Spin up a fresh new WordPress installation with Laravel Valet.
#!/bin/bash
# Script is run from Sites folder
echo "Ensure project is run from Sites folder."
read -p 'New project directory: ' projectName
# Create the directory
echo "Creating directory"
mkdir $projectName
# Set up Valet
@Web-Assembler
Web-Assembler / weba_dropdown_pages_change_args.php
Created November 3, 2022 14:08
WordPress - Add private/draft/future/pending pages to parent dropdown when setting page parent in the Page Attributes/Quick Editor
<?php
/**
* Add private/draft/future/pending pages to parent dropdown when setting
* page parent in the Page Attributes/Quick Editor
*
* @since 3.3.0
*
* @see wp_dropdown_pages()
*
@Web-Assembler
Web-Assembler / webpack.config.js
Last active July 20, 2021 21:03
Webpack for Wordpress
// Theme folder installed at wp-content/themes/mytheme/assets/
// Folder hierarchy as follows:
// assets
// -- js
// ---- admin.js
// ---- public.js
// -- scss
// ---- main.scss
@Web-Assembler
Web-Assembler / woocommerce-sort-product-attributes-table.php
Last active April 29, 2021 09:00
Woocommerce sort Products > Attributes Table Labels
<?php
/**
* The following snippets allow you to custom-sort the Product Attributes Labels (i.e Attribute Taxonomy) in the table inside Products > Attributes.
* WooCommerce allows you to sort the terms of the Attribute but not the order of the Attributes themselves.
* Details on this thread: https://wordpress.org/support/topic/sorting-of-product-attributes/
* I have made my own "hack" solution that allows you to do this. You simply add a number followed by an underscore next to the Attribute Label. e.g. 100_My Attribute Name. If you wish to place another value above this you can use any number below 100 e.g. 67_My Other Attribute Name
*
* The array of values is sorted on this number and removed from displaying on the front end and when editing a product.
* Please be aware this is work in progress code and shouldn't be used on a live site without lots of testing.
*/
@Web-Assembler
Web-Assembler / projectinit.sh
Last active July 12, 2021 20:38
WP CLI Project Setup - Development
#!/bin/bash
## WP CLI Project Setup
# Options documentation here:
# https://codex.wordpress.org/User:HEngel/Option_Reference#Reading
##############
# Instructions
##############
# 1. If the CLI returns an error "error establishing a database connection", change `localhost` in wp-config.php to `127.0.0.1`