Skip to content

Instantly share code, notes, and snippets.

View uddhabh's full-sized avatar

Uddhab Haldar uddhabh

View GitHub Profile
@uddhabh
uddhabh / elementor-close-accordion-by-default.html
Last active July 2, 2023 13:44
Elementor Close Accordion by default
<!-- Source: https://element.how/elementor-close-accordion-on-page-load/ -->
<style class="accordion-closed-on-load">
body:not(.elementor-editor-active) .elementor-widget-accordion .elementor-tab-content {
display: none!important;
}
</style>
<script>
window.addEventListener('load', function() {
setTimeout(function(){
document.querySelector('.accordion-closed-on-load').remove();
@uddhabh
uddhabh / elementor-nested-tab-remember-index.html
Created March 10, 2023 04:33
Remembering Active Tabs in Elementor Nested Tabs using Local Storage and jQuery
<script>
jQuery(document).ready(function () {
localStorage.removeItem('data-tab-index"')
jQuery(".child-tab .e-n-tab-title").click(function () {
localStorage.setItem("data-tab-index", jQuery(this).attr("data-tab"))
})
jQuery(".parent-tab .e-n-tab-title").click(function () {
@uddhabh
uddhabh / disable-right-click-and-dragging.js
Created February 19, 2023 05:25
Disable right-click and dragging on images
function disableRightClickAndDragOnImages() {
// Get all images on the page
const images = document.getElementsByTagName('img');
// Loop through the images and disable right-click and dragging on each one
for (let i = 0; i < images.length; i++) {
images[i].addEventListener('contextmenu', event => {
event.preventDefault();
});
images[i].addEventListener('mousedown', event => {
@uddhabh
uddhabh / rank-math-custom-variable.php
Created February 19, 2023 05:24
Register Custom Variable for Rank Math (state_slug)
<?php
add_action( 'rank_math/vars/register_extra_replacements', function() {
rank_math_register_var_replacement(
'state_slug',
[
'name' => esc_html__( 'State Slug', 'rank-math' ),
'description' => esc_html__( 'Displays the slug of the States custom taxonomy in uppercase.', 'rank-math' ),
'variable' => 'state_slug',
'example' => 'VA',
],
@uddhabh
uddhabh / latest-posts-shortcode.php
Last active February 18, 2023 05:52
This PHP code defines a shortcode function that retrieves the latest posts from a WordPress site's API and displays them in a specific format on a webpage. It uses a transient to store the latest posts for a certain time period to improve performance. The shortcode can be added to a WordPress page or post using the add_shortcode function.
<?php
function latest_posts_shortcode() {
// Set the transient key and expiration time
$transient_key = 'latest_posts';
$expiration = DAY_IN_SECONDS;
// Define the site URL and number of posts per page
$site_url = 'https://example.com';
$posts_per_page = 3;
@uddhabh
uddhabh / FAQ with Search Filtering.html
Last active October 31, 2022 06:44
Elementor FAQ with Search Filtering
<!-- https://element.how/elementor-faq-with-search-filtering/ -->
<div class="faqContainer">
<input type="text" class="faqInput" placeholder="enter keyword...">
<i class="faqReset"></i>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
document.addEventListener('DOMContentLoaded',function(){let settings={toggleOpenOnSearch:true,itemsShownByDefault:10,messages:{noMatchesFound:'No matches found',oneMatchFound:'Showing 1 item',matchesFound:function(){return`Showing ${maxDisplayLimit}of ${matches}items`},allMatchesShown:function(){return`Showing ${sortedList.length}items`},},}
let list=Array.from(document.querySelectorAll('.elementor-toggle .elementor-toggle-item')),filteredList=[],searchTerm,searchTerms,itemText,displayLimit=settings.itemsShownByDefault,loadMoreAmount=settings.itemsShownByDef
@uddhabh
uddhabh / List all posts in custom post type by taxonomy.php
Created October 23, 2022 08:55
List all posts in custom post type by taxonomy
<?php
// https://wordpress.stackexchange.com/questions/66219/list-all-posts-in-custom-post-type-by-taxonomy
$custom_terms = get_terms('states');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'cities',
'tax_query' => array(
array(
'taxonomy' => 'states',
@uddhabh
uddhabh / image gallery item aspect ratio square 1:1.css
Created March 1, 2022 17:47
image gallery item aspect ratio square 1:1
@uddhabh
uddhabh / php.ini
Created February 12, 2022 16:54
Recommended PHP Config for WordPress
memory_limit = 128M;
post_max_size = 64M;
max_execution_time = 120;
upload_max_filesize = 64M;
max_input_time = 60;
max_input_vars = 1000;
(function ($) {
'use strict';
/*===================================
= Menu Activeion =
===================================*/
var cururl = window.location.pathname;
var curpage = cururl.substr(cururl.lastIndexOf('/') + 1);
var hash = window.location.hash.substr(1);
if ((curpage == '' || curpage == '/' || curpage == 'admin') && hash == '') {