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';
<?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 );
@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 / 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'] );
@thisbit
thisbit / custom_hook_shortcode.php
Created February 1, 2022 15:19
Custom Hook in Shortcode
<?php
// place [content_here] shortcode where you want to place your hooked element
function apuri_hero_hook_function( $atts, $content = null ) {
ob_start();
do_action( 'prefix_content_here' );
return ob_get_clean();
}
@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 / create_and_insert_custom_hook_for_mobile_only.php
Created February 7, 2022 10:19
Create a custom hook for mobile version at the bottom of the site, to insert a block element into there.
// not sure if this is ok, but it works on my local generatepress site
function prefix_mobile_quicklinks() {
if ( wp_is_mobile() && function_exists( 'generate_after_footer' ) ) :
do_action( 'mobile_quicklinks' );
endif;
}
add_action( 'generate_after_footer', 'prefix_mobile_quicklinks' );
@thisbit
thisbit / svg_support.php
Created February 17, 2022 15:06
svg support for wordpress media upload
<?php
function add_svg_to_upload_mimes( $upload_mimes ) {
$upload_mimes['svg'] = 'image/svg+xml';
$upload_mimes['svgz'] = 'image/svg+xml';
return $upload_mimes;
}
add_filter( 'upload_mimes', 'add_svg_to_upload_mimes', 10, 1 );