WordPress Tricks

Click on Link and Scroll to ID: Fix Overlapping issue of top fixed header

Sometimes you face issue where Top fixed header overlap the portion of the Target. To fix the issue you can use this jquery code. You need to have good understanding about how to use it. Or do a comments if you need help

You need to change the Parent Element ID or Class in the provided code

 jQuery('Parent Element ID or Class').on('click', 'a', function(e){
		   e.preventDefault();
		   e.stopImmediatePropagation();
	var id=	jQuery(this).attr('href');
		 console.log(id);
 jQuery('html,body').animate({scrollTop: jQuery(id).offset().top -180},'slow');
	   });
WordPress Tricks

Media display settings set “Link to” “Media File” or “None” by default

I am sharing you the code to do this

set Link To “Media File”

add_action( 'after_setup_theme', 'default_attachment_display_settings' );
function default_attachment_display_settings() {
	update_option( 'image_default_link_type', 'file' );
}

set Link To “None”

add_action( 'after_setup_theme', 'default_attachment_display_settings' );
function default_attachment_display_settings() {
	update_option( 'image_default_link_type', 'none' );
}
WordPress Tricks

How to Add a product search form in woocommerce Category page

Here I am sharing you the code to show a product search form in woocommerce category page. You need to put the code in functions.php page

adding product search form in woocommmerce product category page
add_action( 'woocommerce_before_shop_loop', 'my_woocommerce_before_shop_loop' );

function my_woocommerce_before_shop_loop() {
    if ( is_tax( 'product_cat' )   ) {?>

<div class="et_pb_row et_pb_row_0 et_pb_equal_columns et_pb_gutters3 productsearch">						
<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/'  ) ); ?>">
	<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
	<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />
	<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
	<input type="hidden" name="post_type" value="product" />
</form>						
						</div>
<?php
         
    }
}
WordPress Tricks

WordPress Copy Content Protection: Protect Specific page to be copied and disable CTRL+C, CTRL+V using jQuery and Javascript

Here I am sharing you a code snippet which you can use to protect your specific page to be copied. This Code will disable Right Click, CTRL+C and CTRL+V etc. I got this code from StackOverflow.com and modified it a little so that you can use it for your WordPress Page.

Just change the Page ID in the code with your own page ID which you want to be protected.

<?php
	if(is_page('YOUR PAGE ID')){?>
<script>

jQuery(document).ready(function() {
 jQuery(function() {
       jQuery(this).bind("contextmenu", function(e) {
            e.preventDefault();
        });
    });
});
	
// Disable Right click
document.addEventListener('contextmenu', event => event.preventDefault());

// Disable key down
document.onkeydown = disableSelectCopy;

// Disable mouse down
document.onmousedown = dMDown;

// Disable click
document.onclick = dOClick;

function dMDown(e) { return false; }

function dOClick() { return true; }

function disableSelectCopy(e) {
    // current pressed key
    var pressedKey = String.fromCharCode(e.keyCode).toLowerCase();
    if ((e.ctrlKey && (pressedKey == "c" || pressedKey == "x" || pressedKey == "v" || pressedKey == "a" || pressedKey == "u")) ||  e.keyCode == 123) {
        return false;
    }
}	
	
</script>
<?php } ?>	
WordPress Tricks

Woocommerce shortcode to show product image, sku, regular price, sales price, title using wp_Query

Here I am sharing you the code to see how it works. The shortcode will be [strong_overstock_products]

function strong_overstock_products_output(){
 $args = array(
        'post_type'      => 'product',
         'product_cat'    => 'overstock'
    );

    $loop = new WP_Query( $args );
?>
 
<ul class="txt">
<?php
    while ( $loop->have_posts() ) : $loop->the_post();
        global $product;
	 $sku = get_post_meta( get_the_ID(), '_sku', true );
	echo '<li class="wc-taxonomy-child">' ;
        echo '<br /><a href="'.get_permalink().'">' . woocommerce_get_product_thumbnail().'<div class="taxc-product--overlay">
                            <div>
			                    VIEW PRODUCT                            </div>
                        </div>'.' </a>';
	echo "<div class='sku'>SKU : ".$sku."</div>";
	  echo ' <a href="'.get_permalink().'">' .get_the_title().'</a>';
   $pricer = get_post_meta( get_the_ID(), '_regular_price', true );
	$prices = get_post_meta( get_the_ID(), '_sale_price', true );
if ( $product->is_on_sale()) {
                 echo '<p class="taxc-product--price">
                    <del aria-hidden="true"><span class="woocommerce-Price-amount amount"><bdi> ' .$pricer.'</bdi></span></del> <ins><span class="woocommerce-Price-amount amount"><bdi>' .$prices . ' </bdi></span></ins> </p>';
            } else {
                 echo '<p class="taxc-product--price">
                      <ins><span class="woocommerce-Price-amount amount"><bdi>' .$pricer . ' </bdi></span></ins> </p>';
            }
	
	?>
	 
		
<?php	
	echo '</li>' ;
	endwhile;
	?>
</ul>	
<?php	

    wp_reset_query();
}

add_shortcode('strong_overstock_products', 'strong_overstock_products_output');
WordPress Tricks

Multi Blog By themeinwp :Photography Fashion or food blog and Modification of header footer sidebar using css

Multi Blog by ThemeinWp is a responsive WordPress theme which you can use for personal, travel, fashion, food, photography, publishing, tutorial blogs, or any other site. If you are a creative blogger,then you can use this theme. Here I am sharing you some css tips which you can use to modify the header, footer, sidebar, font color, font family and more using css. You can download MultiBlog by Themeinwp, Or you can see the demo of Multi Blog theme. If you have any question regarding css helps, feel free to ask question in comments section

Continue reading “Multi Blog By themeinwp :Photography Fashion or food blog and Modification of header footer sidebar using css”
WordPress Tricks

WordPress Twenty Twenty-Two theme By the WordPress team : Modify header and content width using css

Here I am sharing you 2 technique using css. Please Feel Free to do comments if you have any question regarding Twenty Twenty Two theme of wordpress by Automattic.

1 ) To change font size, color and font family and spacing of H1 header tag for Page titles

h1 {
    font-family: cursive !IMPORTANT;
    color: darkred;
    font-size: 25px !important;
    margin-bottom: 12px !IMPORTANT;
    margin-top: 12px !IMPORTANT;
}

2) To make contents full width using css in Twenty Twenty Two theme

.wp-block-post-content > * {
    max-width: 1022px !important;
}

3) Reduce space between two blog posts using css in Twenty Twenty two theme

.blog .wp-block-group .wp-block-spacer {
    height: 50px !important;
}

4) To reduce gap at the top of Leave A Reply Comment box in Twenty Twenty Two theme

.wp-block-post-comments {
    margin-top: 0px !IMPORTANT;
    padding-top: 0px !important;
}

5) To change font size, color, font family, font weight and using background color and alignment of “Leave a Reply” in twenty twenty two theme

h3#reply-title {
    font-size: 25px;
    color: white !IMPORTANT;
    font-weight: bold;
    font-family: cursive !important;
    background: green;
    padding: 12px;
    text-align: center;
}

6) To Change font size, background color of this Post Comment button

input#submit {
    background: darkred;
    font-size: 14px;
    font-weight: bold;
} 

7) If you don’t want to show comments date in your blog post in Twenty Twenty Two theme

.comment-metadata {
    display: none;
}

8) If you want to change font size, color and font family of comments author in twenty twenty two theme

.comment-author, .comment-author * {
    font-size: 16px !IMPORTANT;
    color: darkblue;
    font-family: cursive;
}

9) If you want to make body background red and content header and footer background white

.wp-site-blocks header {
    background: white;
}
.wp-site-blocks main {
    background: white;
    margin-top: 0px;
}
.wp-site-blocks footer {
    background: white;
    margin-top: 0px !IMPORTANT;
    padding-top: 0px !IMPORTANT;
}
body {
    background: red;
}
WordPress Tricks

Add additional Continue Shopping button beside View Cart which linked to the Added Product Category page

Just wanted to add an additional button in the woocommerce message bar and beside the View Cart button, which will be linked to the added product category page.

function filter_wc_add_to_cart_message_html( $message, $products ) { 
global $wp_query;
//echo $products[0] ;
$catID=array_keys($products);
$catID=$catID[0];
 	
 $terms = get_the_terms($catID, 'product_cat' );
 
 
foreach ($terms  as $term  ) {
            $product_cat_id = $term->term_id;
            $product_cat_name = $term->name;
            break;
        }	
$productCategoryUrl = get_category_link($product_cat_id);	
 
 $continue   = '<a href="'.$productCategoryUrl.'" class="button wc-forward cat"> Continue shopping </a>'; 
        
    $message .= $continue;
    return $message; 
}; 

add_filter( 'wc_add_to_cart_message_html', 'filter_wc_add_to_cart_message_html', 10, 2 );
WordPress Tricks

Show custom dropdown based on visited url in woocommerce category page

Suppose in some specific url ( mainly your product category page url) you want to show some specific or customize dropdown. Here I am sharing you such code which you can use by customizing it.

add_action( 'woocommerce_before_shop_loop', 'showcustomdropdown', 31 );
 
function showcustomdropdown() {      
   if ( is_product_category() ) {      
     // wc_product_dropdown_categories();
	$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];


if ((strpos($url,'?product_cat=wall-mounted+single-zone') !== false) || strpos($url,'?product_cat=floor-mounted+single-zone') !== false || strpos($url,'?product_cat=ceilling-cassettes+single-zone') !== false || strpos($url,'?product_cat=concealed-duct+single-zone') !== false || strpos($url,'/mini-split-ac/single-zone/') !== false)  {
	echo "<select id='product_cat'>";
	echo '<option value=" ">'."Select Category"."</option>"; 
   echo '<option value="?product_cat=wall-mounted+single-zone">'. "Wall Mounted" .  '</option>';
	echo '<option value="?product_cat=floor-mounted+single-zone">'."Floor Mounted"  .  '</option>';
	echo '<option value="?product_cat=ceilling-cassettes+single-zone">'. "Ceilling Cassettes" .  '</option>';
	echo '<option value="?product_cat=concealed-duct+single-zone">'. "Concealed Duct" .  '</option>';
	echo "</select>";
} else {
    
}
	   
   } 
   wc_enqueue_js( "
      $('#product_cat').change(function () {
         location.href = '/shop/' + $(this).val();
      });
   " );
}
WordPress Tricks

WordPress theme Zoologist by Automattic: CSS Customization of header, footer, contents and more

Zoologist by Automattic
Image Courtesy WordPress.com

Zoologist  by Automattic is a simple single column theme. If you are searching for a single column layout theme with basic design then this theme can be a good choice for you. Here I am going to share you CSS tricks to modify header, footer, fonts style and more.

Live Demo of Zoologist by Automattic

If you want to install it in your self hosted wordpress site, you can download them from WordPress.com repository.

Download Zoologist Parent theme Blockbase

Download Zoologist Child theme

Also You need to Install Gutenberg Plugins by Gutenberg Team

So, Here I am sharing you the css tricks which you can use to change the style of the theme.

Continue reading “WordPress theme Zoologist by Automattic: CSS Customization of header, footer, contents and more”