Skip to content

Instantly share code, notes, and snippets.

View lucasmshepherd's full-sized avatar
👽

Lucas M. Shepherd lucasmshepherd

👽
View GitHub Profile
<?php
/*
Plugin Name: Example of Button on Admin Page
Plugin URI:
Description:
Author:
Version: 1.0
Author URI:
*/
$pages = array(
$page_onair => array(
'page_id' => -1,
'slug' => 'radio-shows',
'author_id' => 1,
'title' => 'On Air Shows',
'tpl' => 'template-onair.php',
),
$page_weather => array(
'page_id' => -1,
@lucasmshepherd
lucasmshepherd / replace-string.js
Last active November 26, 2021 06:12
Use javascript .replace() to modify strings in order to facilitate different cases. Currently has lowercase and dashcase.
var example = "I am a string";
// lowercase "i am a string"
example = example
.replace(/([A-Z])/g, function($1) { return $1.toLowerCase(); });
// dashcase "i-am-a-string"
example = example
.replace(/\s+/g, "-")
.replace(/([A-Z])/g, function($1) { return $1.toLowerCase(); });
@lucasmshepherd
lucasmshepherd / function
Last active January 15, 2021 14:11
Code for easily changing the title of your Genesis WordPress PHP theme.
<?php
add_action('genesis_post_title', 'genesis_do_post_title');
function genesis_do_post_title() {
if ( is_singular() ) {
$title = sprintf(
'<h1 class="entry-title">%s</h1>',
apply_filters( 'genesis_post_title_text', get_the_title() )
);
} else {
@lucasmshepherd
lucasmshepherd / index.html
Created July 23, 2020 19:59
HTML5 Template for custom projects. Includes stylesheet media, jquery and standard HTML5 nesting.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Simple HTML5 Skeleton Template</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" media="print" href="print.css">
</head>
@lucasmshepherd
lucasmshepherd / Example.jsx
Last active January 15, 2021 14:11
When you press a primary button there is a class added to a secondary element. Handy for overlays and all sorts of onClick animations.
import React, { Component } from "react";
export default class exampleClass extends Component {
addClassOnClick() {
let elementToAddClass = document.getElementById("exampleID");
if (elementToAddClass) {
elementToAddClass.classList.toggle("exampleClass");
} else {
console.log("No element found");
@lucasmshepherd
lucasmshepherd / example-plugin.php
Last active January 15, 2021 14:12
This is a blank template for creating a custom plugin. Create a directory i.e. 'wp-content/plugins/example-plugin/' then add your plugin function file in that folder i.e. 'example-plugin.php' then paste the code below and have some fun!
<?php
/**
* Plugin Name: Example Plugin by Lucas Grey
* Description: Example plugin.
* Author: Lucas Grey
* Version: 1.0.0
*/
@lucasmshepherd
lucasmshepherd / cartTotals.php
Last active January 15, 2021 14:12
A simple snippet for adding cart count & total to WooCommerce pages.
<?php global $woocommerce; ?>
<a class="your-class-name" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('Cart View', 'woothemes'); ?>">
<?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> -
<?php echo $woocommerce->cart->get_cart_total(); ?>
</a>
@lucasmshepherd
lucasmshepherd / functions.php
Last active January 15, 2021 14:12
WooCommerce. Remove Filtering from Products. Remove product results count, and more...
// Remove filtering on product page
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
// Remove result count
remove_action( 'woocommerce_before_shop_loop' , 'woocommerce_result_count', 20 );
// Remove product image zoom
remove_theme_support( 'wc-product-gallery-zoom' );
// Remove sale badge from product cards
@lucasmshepherd
lucasmshepherd / extendedUserLoggedIn.php
Last active January 15, 2021 14:12
Show username if logged in or something else if not. Put it where you want the text/html to show up.
<?php global $current_user; wp_get_current_user(); ?>
<?php if ( is_user_logged_in() ) {
echo 'Username: ' . $current_user->user_login . "\n"; echo 'User display name: ' . $current_user->display_name . "\n"; }
else { wp_loginout(); } ?>