Skip to content

Instantly share code, notes, and snippets.

View ajitbohra's full-sized avatar
🎯
Scaling Operations @lubusIN

Ajit Bohra ajitbohra

🎯
Scaling Operations @lubusIN
View GitHub Profile
@ajitbohra
ajitbohra / script.js
Created May 3, 2016 09:46
Force PDF Download
/**
* Forces all PDF links to download automatically, if the browser supports it.
* Otherwise, open the link in a new browser window or tab.
*/
jQuery(document).ready(function($) {
$('a[href$=".pdf"]')
.attr('download', '')
.attr('target', '_blank');
});
@ajitbohra
ajitbohra / functions.php
Created April 1, 2016 13:31
Wordpress update nag
<?php
add_action('admin_menu','wphidenag');
function wphidenag() {
remove_action( 'admin_notices', 'update_nag', 3 );
}
?>
@ajitbohra
ajitbohra / functions.php
Last active May 30, 2017 15:08
Wordpress Adding image size
<?php
add_image_size( 'custom-size', 220, 180 ); // 220 pixels wide by 180 pixels tall, soft proportional crop mode
add_image_size( 'custom-size', 220, 180, true ); // 220 pixels wide by 180 pixels tall, hard crop mode
add_image_size( 'custom-size', 220, 220, array( 'left', 'top' ) ); // Hard crop left top
/*
For Media Library Images (Admin):
--------------------------------
You can also make your custom sizes selectable from your WordPress admin.
@ajitbohra
ajitbohra / functions.php
Created August 20, 2015 17:45
Remove Theme Editor from Appreances
<?php
/*
* Remove theme editor from backend
*/
function remove_editor_menu() {
remove_action('admin_menu', '_add_themes_utility_last', 101);
}
add_action('_admin_menu', 'remove_editor_menu', 1);
?>
@ajitbohra
ajitbohra / functions.php
Last active January 28, 2016 09:20
Removing wootheme update nag
<?php
/**
* Remove the WooThemes Helper plugin nag on admin screen
*/
add_action( 'init', 'lubus_remove_woo_nag' );
function lubus_remove_woo_nag() {
remove_action( 'admin_notices', 'woothemes_updater_notice' );
}
@ajitbohra
ajitbohra / functions.php
Created June 4, 2015 10:24
WooCommerce Removing payment gateway based on country
<?php
// Reomve unsupported payment gateway
function payment_gateway_disable_for_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['instamojo'] ) && $woocommerce->customer->get_country() != 'IN' ) {
unset( $available_gateways['instamojo'] );
}
return $available_gateways;
}
@ajitbohra
ajitbohra / script.js
Created May 25, 2015 18:49
jQuery: SweetAlert throws error logStr is not defined
// This code throws error: logStr is not define
swal({
title: "Problem",
text: "Problem processing request !",
type: "Error"
});
// This code works perfect
// type argument accepts following: error,success,info,warning
// type is case sensitive "Error" in place of "error" will throw error
@ajitbohra
ajitbohra / index.php
Last active March 6, 2024 09:07
mpdf: HTML/CSS to PDF & send pdf via email
<?php
/*
mPDF: Generate PDF from HTML/CSS (Complete Code)
*/
require_once( 'mpdf/mpdf.php'); // Include mdpf
$stylesheet = file_get_contents('assets/css/pdf.css'); // Get css content
$html = '<div id="pdf-content">
Your PDF Content goes here (Text/HTML)
</div>';
.yoast-settings {
display: none;
}
@ajitbohra
ajitbohra / jQuery string & number concatenation.js
Last active August 29, 2015 14:21
jQuery: String & number concatenation returning NaN
//Scenario 1: String & Math calculation
"height :" + $(document).height() - $(window).height();
//Result: NaN
//Scenario 2: String & Math calculation with parentheses
"height :" + ($(document).height() - $(window).height());
//Result: Height : 1870
//Scenario 3: String without match calculation
"Height:" + $(document).height();