Skip to content

Instantly share code, notes, and snippets.

View cameronjonesweb's full-sized avatar
👨‍👦

Cameron Jones cameronjonesweb

👨‍👦
View GitHub Profile
<?php
add_filter( 'user_contactmethods', 'add_kofi_user_contactmehod' );
function add_kofi_user_contactmehod( $methods ) {
$methods['kofi'] = 'Ko-fi Username';
return $methods;
}
function create_kofi_button_from_user_meta() {
$kofi = get_the_author_meta( 'kofi', get_the_author_ID() );
@cameronjonesweb
cameronjonesweb / 404-fix.php
Created May 1, 2021 01:00
Fix 404 pages returning true for have_posts if permalinks have a prefix ie "/news/%postname/"
<?php
function cameronjonesweb_404_fix() {
global $wp_query;
if ( $wp_query->is_404 ) {
$wp_query->posts = array();
$wp_query->current_post = 0;
$wp_query->post = null;
}
}
@cameronjonesweb
cameronjonesweb / php.ini.hbs
Created September 13, 2021 11:40
Prevent var_dump being truncated using Local by Flywheel
xdebug.var_display_max_depth = -1
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1
<?php
/**
* Delete the option setting for the default category
*
* @link https://cameronjonesweb.com.au/blog/how-to-remove-the-uncategorised-category-from-wordpress-and-woocommerce
*/
function cameronjonesweb_delete_default_category_option() {
if ( get_option( 'default_category' ) ) {
delete_option( 'default_category' );
}
@cameronjonesweb
cameronjonesweb / cameronjonesweb-create-admin.php
Last active July 5, 2021 06:17
Automatically create admin user
<?php
/**
* Create an admin user
*/
function cameronjonesweb_create_admin_user() {
$username = 'username';
$password = 'password';
$email = 'email@example.com';
if ( ! username_exists( $username ) && ! email_exists( $email ) ) {
<?php
/**
* Add the custom column to the exporter and the exporter column menu.
*
* @link https://github.com/woocommerce/woocommerce/wiki/Product-CSV-Importer-&-Exporter#adding-custom-export-columns-developers
*
* @param array $columns.
* @return array $columns.
*/
function cameronjonesweb_add_export_columns( $columns ) {
<?php
function cameronjonesweb_jquery_fix() {
// Restore old jQuery.
wp_deregister_script( 'jquery' );
wp_deregister_script( 'jquery-core' );
wp_register_script( 'jquery-core', get_template_directory_uri() . '/includes/js/jquery-1.12.4.min.js', array(), '1.12.4', false );
wp_register_script( 'jquery', false, array( 'jquery-core' ), null, false );
wp_enqueue_script( 'jquery' );
}
@cameronjonesweb
cameronjonesweb / add-script-handle.php
Created April 5, 2018 03:36
Add the script handle to enqueued script tags
<?php
add_filter( 'script_loader_tag', 'cameronjonesweb_add_script_handle', 10, 3 );
function cameronjonesweb_add_script_handle( $tag, $handle, $src ) {
return str_replace( '<script', sprintf(
'<script data-handle="%1$s"',
esc_attr( $handle )
), $tag );
}
<?php
function cameronjonesweb_acf_setup() {
acf_add_options_page(
array(
'page_title' => 'Theme Settings',
'menu_slug' => 'cameronjonesweb-theme-settings',
)
);
acf_add_local_field_group(
array(
@cameronjonesweb
cameronjonesweb / functions.php
Created May 30, 2019 23:14
Preserve taxonomy heirarchy on edit post page
<?php
add_filter('wp_terms_checklist_args', function ($args){
$args['checked_ontop'] = false;
return $args;
});