Skip to content

Instantly share code, notes, and snippets.

View taricco's full-sized avatar

Tim in Seattle taricco

  • Seattle, WA
View GitHub Profile
/*** - Add an "Alt Text" column to the Media Library list view.
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_filter( 'manage_media_columns', function( $columns ) {
// Put it after the title column (tweak position as you like)
$new = [];
foreach ( $columns as $key => $label ) {
$new[ $key ] = $label;
if ( 'title' === $key ) {
$new['wsv_alt_text'] = __( 'Alt Text', 'your-textdomain' );
}
/*** Rewrite the "Category base" and "Tag base"
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_action( 'init', function() {
global $wp_rewrite;
// Set clean category and tag bases
$wp_rewrite->category_base = 'sort-by';
$wp_rewrite->tag_base = 'sort-by/tag';
/*** Remove "automated excerpts" from CPTs
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
/**
* Disable automatic excerpts for specific CPTs.
*/
add_filter( 'get_the_excerpt', function( $excerpt, $post ) {
// List of CPTs that should NOT show excerpts
$blocked_cpts = array(
'cpt1',
calc(-1 * var(--padding-sm))
/*** Block Editor Notices (Single Page)
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_action('enqueue_block_editor_assets', function () {
if ( ! is_admin() ) return;
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
if ( ! $screen || empty($screen->post_type) || $screen->post_type !== 'page' ) return;
$post_id = isset($_GET['post']) ? (int) $_GET['post'] : 0;
$allowed_ids = [8588]; // <-- Insert Post ID(s)
/** Force-enqueue "Orbital" theme GF assets for ALL forms on all single posts/pages/CPTs **/
add_action('wp', function () {
if ( is_admin() ) return; // front-end only
if ( ! is_singular() || is_attachment() ) return; // any single post/page/CPT, skip attachments
// Ensure GF is available
if ( ! function_exists('gravity_form_enqueue_scripts') || ! class_exists('GFAPI') ) return;
$uses_ajax = apply_filters('wsv_gf_force_enqueue_ajax', false); // flip to true if you use AJAX sitewide
/** Populate Gravity Forms form hidden field with ACF field "resource_type" data
NOTE: In the Gravity Forms hidden field, enter "resource_type" as the dynamic population parameter. **/
// Populate GF hidden field with parameter name: resource_type
add_filter('gform_field_value_resource_type', function ($value) {
// Bail if ACF isn't loaded
if ( ! function_exists('get_field') ) {
return $value;
}
// Get a reliable post ID even when the form is injected via hooks/Elements
/*** Add "Reading Time" to Posts
Display with dyanmic template tag {{fn.wsv_read_time_badge}} - https://snippetclub.com/dynamic-template-tags/
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function wsv_calc_read_time($post_id = 0) {
$post_id = $post_id ?: get_the_ID();
$wpm = (int) apply_filters('wsv_read_time_wpm', 225);
if ($wpm < 100) $wpm = 100;
$content = get_post_field('post_content', $post_id);
/*** Add Tags to CPTs
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
// 1) Make these CPTs support post_tag
add_action( 'init', function () {
$post_types = [ 'reports', 'webinars', 'ebooks', 'guidebooks', 'solutions' ];
foreach ( $post_types as $pt ) {
register_taxonomy_for_object_type( 'post_tag', $pt );
}
}, 11 ); // run after CPTs are registered