Skip to content

Instantly share code, notes, and snippets.

View deckerweb's full-sized avatar
🏠
Working from home

David Decker deckerweb

🏠
Working from home
View GitHub Profile
@krstivoja
krstivoja / function.php
Last active April 21, 2023 07:40
Sidebar categories list inside Admin Posts
add_action( 'admin_notices', 'add_html_and_category_filter' );
function add_html_and_category_filter() {
$current_screen = get_current_screen();
if ( $current_screen->id === 'edit-post' && $current_screen->post_type === 'post' ) {
$categories = get_categories();
$current_category_id = isset( $_GET['cat'] ) ? intval( $_GET['cat'] ) : 0;
function add_support_details_widget() {
wp_add_dashboard_widget(
'support_details_widget',
'Support Details',
'support_details_widget_content'
);
}
add_action( 'wp_dashboard_setup', 'add_support_details_widget' );
function support_details_widget_content() {

Just a quick way of hiding the Wordpress admin bar without having to go into the User Settings or turning it off completely. Just add ?nowp to the URL and it's gone. Easy preview without the menu. Especially useful when you have fixed elements like a header which can end up behind this bar

<?php

add_action('wp', 'hide_admin_bar_if_nowp');

function hide_admin_bar_if_nowp() {
    if (isset($_GET['nowp'])) {
 add_filter('show_admin_bar', '__return_false');

Here’s some relevant notes:

Both outer and canvas:

if ( bricks_is_builder() ) {
}

Only outer (this code won’t run in the inner canvas (your actual Page/template)):

if ( bricks_is_builder_main() ) {

The WordPress Codex offers an interesting snippet for a shortcode. First copy the following code into the functions.php of the theme or use WP Code Box:

function wpcodex_hide_email_shortcode( $atts , $content = null ) {
	if ( ! is_email( $content ) ) {
		return;
	}

	return '<a href="mailto:' . antispambot( $content ) . '">' . antispambot( $content ) . '</a>';
}

Just a quick one that will disable the editor on ALL pages and posts, handy if you only use custom fields.

<?php
// Remove the editor from ALL pages and posts
function disable_editor_on_all_pages_and_posts() {
  remove_post_type_support( 'page', 'editor' );
  remove_post_type_support( 'post', 'editor' );
}
add_action( 'admin_init', 'disable_editor_on_all_pages_and_posts' );

Easily set your Basic Text Element to default as

or any other tag. As a bonus, I've added <ul> and <li> tags, so no more chumpin' setting custom code.

Copy and paste the following code into your bricks-child/functions.php:

add_filter('bricks/elements/text-basic/controls', function ($controls) {
    $controls['tag'] = [
        
        'tab'         => 'content',
        'label'       => esc_html__('HTML tag', 'bricks'),
 'type' =&gt; 'select',

Use case #1:

Your client has once again sent you logos that don't meet your requirements (different sizes, sometimes lack transparency, etc.).

Just use the following CSS hack for these logos:

.logo {
	width: 50%;
	aspect-ratio: 3/2;
	object-fit: contain;
	/* to remove e.g. a white background */
@afragen
afragen / stop-auto-update-success-email.php
Last active May 2, 2023 16:52
Stop success update email for plugin/theme auto updates.
<?php
/**
* Stop success email from auto-updates.
*
* @package StopAutoUpdateSuccessEmail
*
* Plugin Name: Stop Auto-update Success Email
* Plugin URI: https://gist.github.com/afragen/e2f40ed2e71e590a127e8adc1db05948
* Description: Stop success email from auto-updates.
* Version: 0.2.0
<?php
/**
* Plugin Name: GlotPress for Git Updater
* Plugin URI: https://gist.github.com/afragen/4574e1ce54a621351e5eb18ac686f8f3
* Description: This plugin is used for site testing.
* Version: 0.1
* Author: Andy Fragen
* License: MIT
* Requires at least: 5.2
* Requires PHP: 7.1