Skip to content

Instantly share code, notes, and snippets.

View Daniel-Walsh's full-sized avatar
So much to code, so little sleep...

Dan Walsh Daniel-Walsh

So much to code, so little sleep...
View GitHub Profile
@Daniel-Walsh
Daniel-Walsh / add-page-template-as-body-class.php
Last active October 1, 2021 02:28
Adds the current page template filename to the body classes #wordpress #php
<?php
/**
* Function : add_page_template_body_class
* Description : Adds the current page template filename to the body classes.
* Author : Dan Walsh
*
* @param array $classes : The array of classes attached to the body element.
*/
function add_page_template_body_class( $classes ) {
global $post;
@Daniel-Walsh
Daniel-Walsh / calculate-speed.js
Last active October 1, 2021 02:28
Calculate the animation time of an element, based on the distance and speed it should travel #javascript #animation
// set your global speed
const speed = 50;
// original position
const x1 = 334;
const y1 = 644;
// new position
const x2 = 182;
const y2 = 598;
@Daniel-Walsh
Daniel-Walsh / get-human-filesize.php
Last active October 1, 2021 02:28
Returns a human readable filesize, given a filesize in bytes #php
<?php
/**
* Returns a human readable filesize, given a filesize in bytes.
*
* @param integer $bytes The filesize to convert in bytes.
* @param integer $decimals The number of decimal places to return. Default is 2.
* @return string
*/
function get_human_filesize( $bytes, $decimals = 2 ) {
$size = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
@Daniel-Walsh
Daniel-Walsh / deregister-category-from-posts.php
Last active October 1, 2021 02:28
Deregister the WordPress core 'category' and/or 'tag' taxonomy from the core 'post' post type #wordpress #php
<?php
// Deregister the 'category' taxonomy from the default 'post' post type.
add_action(
'init',
function () {
unregister_taxonomy_for_object_type( 'category', 'post' );
}
);
@Daniel-Walsh
Daniel-Walsh / yoast-remove-current-page-from-breadcrumbs-via-array.php
Last active November 2, 2023 13:08
Remove the current page from Yoast breadcrumbs #wordpress #php #seo
<?php
// Remove the current page from the Yoast breadcrumb trail, rendering the parent crumb in plain text.
add_filter(
'wpseo_breadcrumb_links',
function ( $links ) {
if ( sizeof( $links ) > 1 ) {
array_pop( $links );
}
return $links;
}
@Daniel-Walsh
Daniel-Walsh / add-favicon-to-wp-admin.php
Created April 30, 2020 10:00
Add a custom favicon to wp-admin #wordpress #php
<?php
// Adds a custom PNG favicon the the wp-admin area of WordPress.
add_action(
'admin_head',
function () {
echo '<link rel="icon" type="image/png" sizes="16x16" href="' . get_template_directory_uri() . '/favicon.png">';
}
);
// Adds a custom ICO favicon the the wp-admin area of WordPress.
@Daniel-Walsh
Daniel-Walsh / dump-query-vars.php
Created May 1, 2020 05:02
Dump the query vars of the current page #wordpress #php
<?php
global $wp_query;
var_dump( $wp_query->query_vars );
@Daniel-Walsh
Daniel-Walsh / add-client-company-field-to-settings.php
Created May 1, 2020 05:09
Add a client/company name field to general settings #wordpress #php
<?php
// Add the 'Client/Company Name' field to General Settings.
add_filter(
'admin_init',
function () {
register_setting(
'general',
'namespace_client_name',
'esc_attr'
);
@Daniel-Walsh
Daniel-Walsh / basic-post-pagination-template-part.php
Last active October 1, 2021 02:28
Basic post pagination template #wordpress #php #pagination
<?php
/**
* Pagination template part.
*
* Injects the required classes to properly render accessible pagination buttons akin to the theme. Uses Bootstrap 4 and Fontawesome.
*
* @package WordPress
*/
$paginate_classes = ' btn btn-primary btn-sm py-2 px-3 mx-1 ';
@Daniel-Walsh
Daniel-Walsh / bootstrap-4-callouts.scss
Last active October 1, 2021 02:28
Callout SCSS rules for Bootstrap 4 #bootstrap4 #scss #css
/**
* Import Bootstrap
*/
@import "../../node_modules/bootstrap/scss/bootstrap";
/**
* Callouts
*/