Skip to content

Instantly share code, notes, and snippets.

View thisbit's full-sized avatar

thisbit thisbit

View GitHub Profile
@thisbit
thisbit / wp_db_cleanup.sql
Last active August 10, 2020 09:11
wp database cleanup and optimization
-- This list of sql commands cleans and optimized a wordpress database, good for speed and functionality in general
-- Remember in each query to replace table prefix with the one you are using
-- Remove post revisions
DELETE FROM wp_posts WHERE post_type = "revision";
-- Remove comments marked as spam
DELETE FROM wp_comments WHERE comment_approved = 'spam';
-- Remove unapproved comments
DELETE from wp_comments WHERE comment_approved = '0';
@thisbit
thisbit / copy-current-url.html
Created January 17, 2021 09:54
copy current url link
<!doctype html>
<html>
<head>
<script>
function Copy() {
var Url = document.getElementById("url");
Url.innerHTML = window.location.href;
console.log(Url.innerHTML)
Url.select();
document.execCommand("copy");
<?php
function myprefix_get_attachment_alt( $attachment_ID ) {
// Get ALT
$thumb_alt = get_post_meta( $attachment_ID, '_wp_attachment_image_alt', true );
// No ALT supplied get attachment info
if ( empty( $thumb_alt ) )
$attachment = get_post( $attachment_ID );
<?php
// work in progress
// WP php script
// create a list of direct links to files via atattchment post type
// manage documents with media library
// have the documents appear in search results via attatchment post type
// made to work with https://wordpress.org/plugins/media-library-organizer/ because it has a more user friendly UI for handling media organisation AND it uses simple taxonomy rather then some similar, maybe better plugins
// If one wants to use it without the plugin uncomment the following block in order to create taxonomies for attatchment post type, and modify the args accordingly
@thisbit
thisbit / ffmpeg_resizeimg.sh
Created December 7, 2021 13:10
A simple script for image optimization using FFMPEG (read the comment)
#!/bin/bash
echo "WARNING: run this in the folder that contains images"
read -p "# IMAGE FILETYPE (type number):
(1) jpg
(2) png
(3) tif
(4) all (WARN: works only on raster images)
: " format
@thisbit
thisbit / hd-just-in-time-css.php
Created January 12, 2022 13:42 — forked from wpmark/hd-just-in-time-css.php
A plugin to provide Just in Time CSS for WordPress blocks
<?php
/*
Plugin Name: Just in Time CSS
Plugin URI: https://highrise.digital/
Description: A plugin from Highrise Digital to provide just in time CSS functionality.
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital Ltd
Author URI: https://highrise.digital/
Text domain: hd-just-in-time-css
@thisbit
thisbit / hide_gutenberg_for_nonadmins.php
Created January 12, 2022 16:12
Hide content field in post, or hide gutenberg from non admins
<?php
// this snippet extends the acf ability to hide content field with user based condition
// usecase: if a layout of posts_type is built with gutenberg,
// but one wants editor user group to not touch it while being able to inpt data via ACF fields
// use this in conjunction with acf shortcodes in the gutenberg layout
// this way admin can adapt and change layouts with ease making sure edtors do not interact with layouts
function thisbit_remove_post_type_support() {
@thisbit
thisbit / random_image_hero.php
Last active February 4, 2022 18:52
Random image header with Generatepress Premium and ACF free or ACF PRO
<?php
// Set the options page (Depends on ACF Pro)
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Home Page Hero Settings',
'menu_title' => 'Home Hero',
'menu_slug' => 'home-hero-settings',
'capability' => 'edit_posts',
@thisbit
thisbit / gp-footer-bottom.css
Created January 18, 2022 12:03
fit generatepress footer to bottom
<?php
// best put in theme that depends on certain plugins
add_filter( 'plugin_action_links', 'disable_plugin_deactivation', 10, 4 );
function disable_plugin_deactivation( $actions, $plugin_file, $plugin_data, $context ) {
if ( array_key_exists( 'deactivate', $actions ) && in_array( $plugin_file, array(
'advanced-custom-fields/acf.php',
'gp-premium/gp-premium.php'
)))
unset( $actions['deactivate'] );