Skip to content

Instantly share code, notes, and snippets.

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

Joy Chetry joychetry

🏠
Working from home
View GitHub Profile
@joychetry
joychetry / single.php
Created April 16, 2024 08:28
Prompt native sharing options inside a post page
<script>
document.addEventListener('DOMContentLoaded', function() {
// Click event listener for images with class 'shareLink'
const images = document.querySelectorAll('.shareLink');
images.forEach(function(image) {
image.addEventListener('click', function() {
const link = document.URL;
// Check if Web Share API is supported
if (navigator.share) {
@joychetry
joychetry / loop-page.php
Last active April 16, 2024 08:26
Prompt native sharing options inside a post loop
<script>
document.addEventListener('DOMContentLoaded', function() {
// Click event listener for images with class 'shareLink'
const images = document.querySelectorAll('.shareLink');
images.forEach(function(image) {
image.addEventListener('click', function() {
const link = this.getAttribute('data-link');
const postTitle = this.getAttribute('data-title'); // Assuming 'data-title' attribute contains the post title
// Check if Web Share API is supported
@joychetry
joychetry / function.php
Created April 2, 2024 08:30
Bricks Builder: Custom Query Option
<?php
/* Add new query type controls to query options */
add_filter( 'bricks/setup/control_options', 'bl_setup_query_controls');
function bl_setup_query_controls( $control_options ) {
/* Adding new options in the dropdown */
$control_options['queryTypes']['goodmonks_crp_query'] = esc_html__( 'GoodMonks: CRP' );
return $control_options;
@joychetry
joychetry / function.php
Created April 2, 2024 08:29
Bricks Builder: Remove URL From Comments
<?php
add_filter( 'comment_form_fields', 'c_customize_bricks_comment_form_fields' );
function c_customize_bricks_comment_form_fields($fields) {
if(isset($fields['url'])){
unset( $fields['url'] ); // remove Comment Author URL field
}
return $fields;
}
@joychetry
joychetry / functions.php
Created April 2, 2024 08:21
Bricks Builder: Avoid blank screen on inside editor.
<?php
//Your code wrapped inside this condition
if( !bricks_is_builder() && !current_user_can('administrator') ){
//Your code here
}
@joychetry
joychetry / functions.php
Created April 20, 2020 10:08
Pull First Image as Featured Image if Featured Image is NA
/* START - Pull First Image as Featured Image if Featured Image is NA */
function crowwwn_auto_featured_image() {
global $post;
if (!has_post_thumbnail($post->ID)) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
@joychetry
joychetry / index.html
Created July 20, 2022 15:26
Dark Mode Switch
<div class="toggle-switch">
<label for="darkSwitch">
<input type="checkbox" id="darkSwitch" />
<span class="toggle-slider"></span>
</label>
</div>
<script>
function initTheme(){var e=null!==localStorage.getItem("darkSwitch")&&"dark"===localStorage.getItem("darkSwitch");darkSwitch.checked=e,e?document.body.setAttribute("data-theme","dark"):document.body.removeAttribute("data-theme")}function resetTheme(){darkSwitch.checked?(document.body.setAttribute("data-theme","dark"),localStorage.setItem("darkSwitch","dark")):(document.body.removeAttribute("data-theme"),localStorage.removeItem("darkSwitch"))}var darkSwitch=document.getElementById("darkSwitch");window.addEventListener("load",function(){darkSwitch&&(initTheme(),darkSwitch.addEventListener("change",function(){resetTheme()}))});
</script>
@joychetry
joychetry / functions.php
Created March 2, 2022 20:22
jQuery Move Div on Mobile
(function($) {
var stickWidth = 768;
var win = $(window);
if (win.width() < stickWidth) {
$('#page-sidebar').insertAfter('#bottom-section');
}
win.resize(function () {
if (win.width() < stickWidth) {
@joychetry
joychetry / functions.php
Last active January 15, 2022 19:46
Insert Thumbnail Before First H2 and Insert Thumbnail After First Paragraph
<?php
//Insert Thumbnail After First Paragraph
add_filter( 'the_content', 'joy_insert_featured_image', 20 );
function insert_featured_image( $content ) {
$content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->ID, 'post-single'), $content, 1 );
return $content;
}
@joychetry
joychetry / functions.php
Created October 27, 2021 14:52
Change WooCommerce Add To Cart Texts
<?php
add_filter( 'add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); // < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); // 2.1 +
function woo_custom_single_add_to_cart_text() {
return __( 'My Button Text', 'woocommerce' );
}