Skip to content

Instantly share code, notes, and snippets.

View kingkool68's full-sized avatar
💻
Coding.

Russell Heimlich kingkool68

💻
Coding.
View GitHub Profile
@kingkool68
kingkool68 / class-coderpad-text-image-block.php
Created April 22, 2022 15:31
How I use Advanced Custom Fields' Blocks to make custom components for WordPress sites. Logic is all in PHP, HTML templating is done in Twig via https://github.com/kingkool68/sprig
<?php
/**
* A block with an image and text on the side
*/
class CoderPad_Text_Image_Block {
/**
* Get an instance of this class
*/
public static function get_instance() {
@kingkool68
kingkool68 / merge-current-branch-to-target-branch.sh
Created February 1, 2022 19:55
Quick little helper script to speed up your Git workflow if you ever need to merge a branch into another frequently (like your current feature branch into a `staging` branch). Useful as a custom command in the Git GUI Fork (https://fork.dev/)
#!/bin/bash
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
TARGET_BRANCH=staging
git fetch origin $TARGET_BRANCH
git checkout $TARGET_BRANCH
git merge "$CURRENT_BRANCH" -m "Merge branch '$CURRENT_BRANCH' into $TARGET_BRANCH"
git push origin $TARGET_BRANCH
git checkout "$CURRENT_BRANCH"
@kingkool68
kingkool68 / wp-config.environments.php
Created November 27, 2021 04:10
Managing `wp-config.php` files for different environments. This allows you to version control your configurations.
<?php
/** Loads environment specific config files for WordPress.
* See https://github.com/studio24/wordpress-multi-env-config and/or http://abandon.ie/notebook/wordpress-configuration-for-multiple-environments
*
* Environment can be:
* 1. Directly loaded via an Environment variable (Name: WP_ENV)
* 2. Looks the ServerName attribute
* 3. Default to production (if no other one is found)
*
* ** Usage **
@kingkool68
kingkool68 / loading-csv-data-for-google-charts.php
Last active October 26, 2021 16:59
James Taylor wanted to load CSV data and display it as a gauge data visualization in WordPress. See https://www.facebook.com/groups/advancedwp/posts/4673874846008026/
<?php
/**
* Plugin Name: River Height Levels
* Plugin URI: https://gist.github.com/kingkool68/567527d28f82bd3a0107970b624fea0a
* Description: Fetch the current river height values and display it as different data visualization.
* Version: 0.0.2
* Author: Russell Heimlich
* Author URI: https://twitter.com/kingkool68
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
<?php
/**
* Load an external CSV file and store it as a transient
*/
function get_the_csv_data() {
$transient_key = 'the-csv-data';
$data = get_transient( $transient_key );
// If the data already exists then return it. We're done here!
if ( false !== $data ) {
<?php
// Expects a page with the slug (aka post_name) set to `post-type` (the same post-type key as the custom post type)
$post = RH_Post_Type_Archives::get_post_type_archive_post();
setup_postdata( $post );
?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
@kingkool68
kingkool68 / virtual-page.php
Created September 21, 2021 17:18
Make WordPress respond to a request for a URL that doesn't actually exist
<?php
/**
* Make WordPress respond to a request for a URL that doesn't actually exist
*/
if ( ! function_exists( 'str_starts_with' ) ) {
/**
* Polyfill for PHP 8's str_starts_with
*
* @link https://php.watch/versions/8.0/str_starts_with-str_ends_with
@kingkool68
kingkool68 / rh-get-widget-data-for-all-sidebars.php
Last active February 15, 2021 03:51
WordPress function to get raw widget data for all of the widgets in a given sidebar
<?php
function rh_get_widget_data_for_all_sidebars() {
global $wp_registered_sidebars;
$output = array();
foreach ( $wp_registered_sidebars as $sidebar ) {
if ( empty( $sidebar['name'] ) ) {
continue;
}
$sidebar_name = $sidebar['name'];
<!doctype html>
<html class="no-js" lang="en-US">
<head>
<meta charset="UTF-8" />
<title>English Learning Programs SSO Logout</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name='robots' content='noindex,nofollow' />
<link rel='stylesheet' id='google-fonts-css' href='https://fonts.googleapis.com/css2?family=Lato:ital@0;1&#038;family=Work+Sans:wght@100;200;300;400;500;600;700;800;900&#038;display=swap' type='text/css' media='all' />

Table of Contents WordPress Plugin

This WordPress plugin creates a table of contents based on the heading structure. It automatically adds anchor links for every heading.

Usage

Use the f1_toc() function to render the table of contents with markup. An optional paramater called limit can be used to only show headings up to a certain level. Example:

// Only show <H1> and <H2> headings in the table of contents