Skip to content

Instantly share code, notes, and snippets.

View junaidbhura's full-sized avatar

Junaid Bhura junaidbhura

View GitHub Profile
@junaidbhura
junaidbhura / index.html
Created March 25, 2023 22:23
Nested Web Components
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Web Components</title>
<style type="text/css">
jb-toggle-buttons {
display: flex;
}
@junaidbhura
junaidbhura / wordpress-404-fallback-post.php
Last active December 2, 2021 03:28
WordPress fallback post instead of 404
<?php
add_action(
'wp',
function () {
global $wp_query;
if ( ! $wp_query->is_main_query() || ! $wp_query->is_404() ) {
return;
}
@junaidbhura
junaidbhura / simple-wp-editor-field.php
Created October 7, 2021 20:19
Simple WordPress Editor Field
<?php
wp_editor(
$speakers,
'my_field',
array(
'media_buttons' => false,
'textarea_rows' => 5,
'tinymce' => array(
'toolbar1' => 'bold, italic, link',
@junaidbhura
junaidbhura / remove-comments.php
Last active August 26, 2020 00:56
WordPress remove comments globally
<?php
/**
* Remove support for comments globally.
*/
function jb_remove_comment_support() {
add_filter( 'comments_open', '__return_false' );
add_filter( 'pings_open', '__return_false' );
$post_types = get_post_types();
if ( ! empty( $post_types ) ) {
<?php
/**
* Serialize an array into a Gutenberg block.
*
* @param array $block Block.
* @return bool|string
*/
function serialize_block( $block = [] ) {
if ( ! isset( $block['blockName'] ) ) {
/**
* Anchors.
*/
// Variables.
import wp from 'wp';
const { addFilter } = wp.hooks;
import includes from 'lodash/includes';
// Add anchor support to these blocks.
@junaidbhura
junaidbhura / gutenberg-button.js
Created August 17, 2019 05:10
WordPress Gutenberg open button in a new window
/**
* Button.
*/
import wp from 'wp';
const { __ } = wp.i18n;
const { addFilter } = wp.hooks;
const { createHigherOrderComponent } = wp.compose;
const { Fragment, cloneElement } = wp.element;
@junaidbhura
junaidbhura / nginx.conf
Created September 20, 2018 07:41
Nginx Remote WordPress Images for Local Development
location ~ ^/wp-content/uploads/[^\/]*/.*$ {
log_not_found off;
try_files $uri $uri/ @production;
}
location @production {
rewrite ^/wp-content/uploads/(.*)$ https://<bucket-name>.s3.amazonaws.com/uploads/$1;
}
@junaidbhura
junaidbhura / .htaccess
Last active September 20, 2018 07:40
Apache Remote WordPress Images for Local Development
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$
RewriteRule ^wp-content/uploads/(.*)$ https://<bucket-name>.s3.amazonaws.com/uploads/$1 [QSA,L]
@junaidbhura
junaidbhura / css-triangle.scss
Last active September 20, 2016 10:33
Sass (SCSS) Mixin to create CSS triangles
@mixin css-triangle( $width: 11px, $height: 7px, $color: '#000', $direction: 'down' ) {
width: 0;
height: 0;
border-style: solid;
@if ( $direction == 'down' ) {
$half-width: $width / 2;
border-width: $height $half-width 0 $half-width;
border-color: $color transparent transparent transparent;
}