Skip to content

Instantly share code, notes, and snippets.

View vishalkakadiya's full-sized avatar
:octocat:

Vishal Kakadiya vishalkakadiya

:octocat:
View GitHub Profile
@vishalkakadiya
vishalkakadiya / functions.php
Created March 13, 2024 10:46
Add User Role based on the CPT
<?php
/**
* Registers the `news` post type.
*/
function news_cpt(): void {
$labels = [
'name' => __( 'News', 'text-domain' ),
'singular_name' => __( 'News', 'text-domain' ),
@vishalkakadiya
vishalkakadiya / reducer.jsx
Last active January 29, 2024 04:01
React Reducer with very Simple Example
import { useReducer } from 'react';
export function counterReducer(state, action) {
if (action.type === 'INCREMENT') {
return {
count: +state.count + 1
};
}
if (action.type === 'DECREMENT') {
@vishalkakadiya
vishalkakadiya / functions.php
Last active October 27, 2023 05:44
WordPress Migration: Convert HTML doms into the common Gutenberg blocks
<?php
/**
* This snippet is useful while doing migration for the WordPress.
* Basically this script will convert the HTML dom into the common Gutenberg block comments,
* so the tags like Pagragraph will be converted into the "<!-- wp:paragraph -->SOME DATA<!-- /wp:paragraph -->".
*
* This script supports paragraph, headings, list tags and many more.
*/
/**
@vishalkakadiya
vishalkakadiya / functions.php
Last active December 12, 2022 16:59
Fix sizes attribute to improve Lighthouse score for core/image and multiple core/images on the page.
<?php
/**
* Modified version of https://core.trac.wordpress.org/attachment/ticket/45985/45985-regular-images.patch patch for testing.
* Full credit goes to that patch owner.
*/
/**
* Add custom `sizes` attribute to responsive image functionality for post content images.
*
* @since Twenty Nineteen 1.0
@vishalkakadiya
vishalkakadiya / functions.php
Last active December 9, 2022 13:32
Fix sizes attribute to improve Lighthouse score for Image gallery with two images.
<?php
/**
* Modified version of https://core.trac.wordpress.org/attachment/ticket/45985/45985-regular-images.patch patch for testing.
* Full credit goes to that patch owner.
*/
/**
* Add custom `sizes` attribute to responsive image functionality for post content images.
*
* @since Twenty Nineteen 1.0
@vishalkakadiya
vishalkakadiya / functions.php
Created September 24, 2021 15:22
WordPress - Add custom filers on backend admin post listing
/**
* Add custom filters.
*/
function custom_filters() {
$post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_STRING );
// Only add filter to post type you want.
if ( 'POST_TYPE_NAME' === $post_type ) {
@vishalkakadiya
vishalkakadiya / mysql(wp)-commands.txt
Last active October 31, 2022 16:48
WordPress(or any mysql database) - Convert special characters(eg. Latin-1) to UTF-8 in mysql database
The actual step-by-step WordPress / MySQL fix…
1. Back up all your stuff first (likely using phpMyAdmin / CPANEL)
Before doing any of the following it strongly encouraged to back up all your data and files. Just to be safe. At the very least, your full database and the WordPress config file: wp-config.php
2. Note the settings that your WordPress is currently using (from wp-config.php)
Specifically, your MySQL database configuration, including DB_NAME, DB_USER, DB_PASSWORD, and also DB_CHARSET and DB_COLLATE
// ** MySQL settings - You can get this info from your web host ** //
@vishalkakadiya
vishalkakadiya / functions.html
Last active May 31, 2021 04:42
Create a Gutenberg block theme
<html>
<body>
<a href="https://developer.wordpress.org/block-editor/how-to-guides/themes/create-block-theme/">https://developer.wordpress.org/block-editor/how-to-guides/themes/create-block-theme/</a>
</body>
</html>
@vishalkakadiya
vishalkakadiya / audio-sample.html
Last active May 5, 2021 11:13
Audio(tag) Player - Play/Pause/Restart/Skip Some Seconds
<!--
Just replace your audio file's name with `file_example_MP3_700KB.mp3` given in below code.
Refs:
- https://stackoverflow.com/questions/29593733/i-want-to-stop-skip-30-seconds-on-audio-in-html
- https://developer.mozilla.org/en-US/docs/Web/Guide/Audio_and_video_delivery/Cross-browser_audio_basics
- https://www.w3schools.com/tags/ref_av_dom.asp
-->
<!DOCTYPE html>
@vishalkakadiya
vishalkakadiya / functions.php
Last active September 24, 2021 05:52
WordPress - Removing Gutenberg block editor from widgets area and make it as before.
/**
* Disabling block editor for widgets.
*/
function example_theme_support() {
remove_theme_support( 'widgets-block-editor' );
}
add_action( 'after_setup_theme', 'example_theme_support' );