Skip to content

Instantly share code, notes, and snippets.

View rabindratharu's full-sized avatar

Rabindra Tharu rabindratharu

  • Kathmandu (Nepal)
View GitHub Profile
@rabindratharu
rabindratharu / functions.php
Created March 21, 2025 10:27 — forked from LearnWebCode/functions.php
WordPress functions to fetch external JSON (and store in transient + option backup) and also functions to setup programmatic URL patterns and use custom template files for said URLs
function get_cached_external_json($url) {
$transient_key = 'our_fetched_json_' . md5($url);
$option_key = 'our_fetched_json_backup_' . md5($url);
$cached_data = get_transient($transient_key);
if (false !== $cached_data) {
return $cached_data;
}
@rabindratharu
rabindratharu / functions.php
Created August 6, 2024 07:12
FSE theme set Site Logo in One Click Demo Import
/**
* Add theme support.
*
* @since 1.0.0
*
* @return void
*/
if ( ! function_exists( 'rabindra_tharu_setup' ) ) {
function rabindra_tharu_setup() {
@rabindratharu
rabindratharu / gist:f1571d44d48bb599f5d4bb4e8eceafcd
Last active July 25, 2024 04:06
Register New Fields in WP GraphQl
add_action( 'graphql_register_types', function() {
// Site Logo
register_graphql_field( 'RootQuery', 'siteLogo', [
'type' => 'MediaItem',
'description' => __( 'The logo set in the customizer', 'your-textdomain' ),
'resolve' => function() {
$logo_id = get_theme_mod( 'custom_logo' );
if ( ! isset( $logo_id ) || ! absint( $logo_id ) ) {
@rabindratharu
rabindratharu / dequeue-scripts.txt
Last active November 30, 2016 05:47
Dequeue Scripts
//Dequeue JavaScripts
function theme_dequeue_unnecessary_scripts() {
wp_dequeue_script( 'jquery-waypoints' );
wp_deregister_script( 'jquery-waypoints' );
wp_dequeue_script( 'jquery-counterup' );
wp_deregister_script( 'jquery-counterup' );
}
add_action( 'wp_print_scripts', 'theme_dequeue_unnecessary_scripts', 100 );