Skip to content

Instantly share code, notes, and snippets.

@barrd
barrd / wordpress-search-order-by-date.php
Created December 24, 2022 11:13
WordPress custom search order by date
<?php
/**
* Custom search order by Date
*
* @param string $orderby Orderby string.
* @param object $query The query.
*/
function barrd_sort_search_by_date( $orderby, $query ) {
global $wpdb;
if ( ! is_admin() && is_search() ) {
@barrd
barrd / starship.toml
Last active July 20, 2022 10:28
Personal config for starship prompt
[character]
success_symbol = "[➜](bold green) "
error_symbol = "[➜](bold red) "
format = "$character$all"
[cmd_duration]
disabled = true
[directory]
@barrd
barrd / barrd.yaml
Created July 14, 2022 06:27
Warp terminal custom theme barrd.yaml
accent: "#258595" # Accent colour for UI elements.
background: "#272c34" # Terminal background colour.
details: darker # Whether the theme is lighter or darker.
foreground: "#b3bac6" # The foreground colour.
terminal_colors: # Ansi escape colours.
bright:
black: "#106378"
blue: "#6cb8f1"
cyan: "#61bec9"
green: "#a2ca84"
@barrd
barrd / add-resuable-blocks-in-admin-menu.php
Created February 19, 2022 17:48
Add reusable Gutenberg blocks into WordPress admin menu
<?php
/**
* Add reusable Gutenberg blocks into WordPress admin menu
*/
function barrd_add_reusable_blocks_admin_menu() {
add_menu_page(
'Reusable Blocks',
'Reusable Blocks',
'edit_posts',
'edit.php?post_type=wp_block',
@barrd
barrd / wordpress-replace-wp-json-api.php
Last active October 17, 2021 06:21
WordPress - Replace wp-json REST API prefix with api
<?php
// Replace the 'wp-json' REST API prefix with 'api'.
// Make sure to flush the rewrite rules for this to work!
// 🔥 Kudos Phil Kurth
// @see https://www.youtube.com/watch?v=vSUi2Rt36yU
add_filter( 'rest_url_prefix', function () {
return 'api';
} );
@barrd
barrd / reuseable-blocks-admin-menu.php
Created May 2, 2021 11:17
WordPress - Add reusable blocks into admin menu
<?php
/**
* Add reusable blocks into admin menu
*
* @link https://www.jemjabella.co.uk/2021/6-things-i-do-to-make-gutenberg-development-easier
*/
function add_reusable_blocks_admin_menu() {
add_menu_page(
'Reusable Blocks',
'Reusable Blocks',
@barrd
barrd / wordpress-search-functions.php
Last active February 6, 2022 11:34
WordPress Search Functions
<?php
/**
* Exclude posts by ID
*
* @param array $query The WP_Query instance.
*/
function exclude_posts_from_search( $query ) {
if ( $query->is_main_query() && is_search() ) {
// Add post IDs into array.
$post_ids = array( 10, 11, 12 );
@barrd
barrd / .gitignore
Created February 24, 2021 17:48
WordPress (Vanilla) Git Ignore File
# ---------------------------------------------------------------------
# Vanilla WordPress Git Ignore File
# ---------------------------------------------------------------------
# Ignore everything in root except wp-content dir & wp-config
/*
!wp-content/
!wp-config*
wp-config-sample.php
@barrd
barrd / wp-load-all-required-dependencies.php
Last active April 16, 2021 18:51
WordPress load all required theme dependencies using RecursiveDirectoryIterator from inc
<?php
/**
* Required Dependencies
*/
// Construct the iterator.
$rdi = new RecursiveDirectoryIterator( get_template_directory() . '/inc' );
// Loop through PHP files.
foreach ( new RecursiveIteratorIterator( $rdi ) as $file ) {
if ( $file->getExtension() === 'php' ) {
@barrd
barrd / wp-hide-jquery-migration-notice.php
Created February 18, 2021 07:31
WordPress hide jQuery migration notice and disable admin email
<?php
/**
 * Hide jQuery Migration notice
 *
 * Temp fix until plugin can be removed
 *
 * @return void
 */
function removes_migrate_warning() {