Skip to content

Instantly share code, notes, and snippets.

View isaumya's full-sized avatar
👨‍💻
Think Twice, Code Once

Saumya Majumder isaumya

👨‍💻
Think Twice, Code Once
View GitHub Profile
@isaumya
isaumya / adding-html-within-php.php
Created September 19, 2016 15:38
Adding HTML within PHP with the help of STR
<?php
/* Option 1 */
$html = '<div>
<p>At the time of creating any blog or news based websites most webmasters gives the least amount of importance to the commenting system of their website, without even understanding the importance of it. Eventually comment section of a website is the only place where people interact with the author when they are exited or happy with the article and helps to grow the whole website community. In most cases they end up using some third party commenting system like Disqus or Spot.im etc. without even realizing what a blunder they are making. I’ve seen many websites (both big & popular as well as small websites) using Disqus commenting system, without even realizing the consequences. And by the time you will realize it, your site would have become so big & popular they you can’t take the risk of changing your commenting system. If you are thinking why, keep reading.</p>
<p><a href="I want to omit this P from counting"><img src="I want to omit this p from counting" /></a></p>
<p
@isaumya
isaumya / functions.php
Created September 19, 2016 15:32
Fix: CSS minification & combination is not working for WordPress sites with mod_pagespeed or ngx_pagespeed
<?php
/*Allowing mod_pagespeed or nginx_pagespeed to combine CSS files*/
/*By removing the ID field from the css link href*/
add_filter('style_loader_tag', function( $link ) {
// Removing the Style ID from the WordPress CSS output as the ID in `link` causes the issue
return preg_replace("/id='.*-css'/", "", $link);
} );
@isaumya
isaumya / functions.php
Created September 19, 2016 15:27
Changing the default loading icon for editing comments for general users in Simple Comment Editing WordPress Plugin
<?php
/**
* Changing the default loading icon for editing comments for general users
* @plugin_name: Simple Comment Editing
* @plugin_uri: https://wordpress.org/plugins/simple-comment-editing/
*/
add_filter( 'sce_loading_img', function( $default_url ) {
return get_stylesheet_directory_uri() . '/assets/images/spinner.gif';
} );
@isaumya
isaumya / functions.php
Created September 19, 2016 15:25
Increase general user comment editing time in Simple Comment Editing WordPress Plugin
<?php
/**
* Increase general user comment editing time
* @plugin_name: Simple Comment Editing
* @plugin_uri: https://wordpress.org/plugins/simple-comment-editing/
*/
add_filter( 'sce_comment_time', function( $time_in_minutes ) {
return 10;
} );
@isaumya
isaumya / functions.php
Created September 19, 2016 15:21
Disable sanitization on Gravity Form for WordPress - prior to v2.0 update
<?php
/* Please note this filter will not work on Gravity Forms v2.0+
* If your GF is not capturing values like ajgsdn?12332#?fds#^%
* then use the following filter in GF v2.0 prior
**/
add_filter( 'gform_sanitize_entry_value', '__return_false' );
@isaumya
isaumya / wp-count-total-paragraph.php
Created September 19, 2016 15:16
Count the total number of paragraph on any WordPress blog post
<?php
function __check_paragraph_count_blog( $content ) {
global $post;
if ( $post->post_type == 'post' ) {
$count = substr_count( $content, '</p>' );
return $count;
} else {
return 0;
}
}
@isaumya
isaumya / wp-insert-ad-code-legacy.php
Created September 19, 2016 15:14
Insert AdSense Ad code after certain paragraph number. Please note that the following code will consider all `p` tags into its consideration while executing
<?php
/*
Plugin Name: Insert AdSense Ad Code after certain paragraph
Plugin URI: https://www.isaumya.com/
Description: Insert AdSense Ad code after certain paragraph number considering all `p` tags
Version: 1.0
Author: Saumya Majumder
Author URI: https://www.isaumya.com/
*/
@isaumya
isaumya / wp-insert-ad-code.php
Created September 19, 2016 15:01
Insert AdSense Ad Code after certain number of paragraphs in your WordPress posts dynamically while ignoring some paragraphs in the paragraph checking/count
<?php
/*
Plugin Name: Insert AdSense Ad Code after certain paragraph
Plugin URI: https://www.isaumya.com/
Description: Insert AdSense Ad code after certain paragraph number while ignoring some paragraphs
Version: 2.0
Author: Saumya Majumder
Author URI: https://www.isaumya.com/
*/
@isaumya
isaumya / functions.php
Created September 16, 2016 08:32
Disable WordPress XMLRPC.php without affecting Jetpack Plugin
<?php
add_filter( 'xmlrpc_enabled', '__return_false' );
@isaumya
isaumya / functions.php
Created September 9, 2016 20:43
Attach files with Gravity Forms Notification Emails - Gravity Forms
<?php
//* Attaching file to the form notification user email
//* in gform_notification_7, the number 7 is the FORM ID
//* This snippet works with the newer version of Gravity Forms too
add_filter('gform_notification_7', 'add_attachment_pdf', 10, 3); //target form id 7, change to your form id
function add_attachment_pdf( $notification, $form, $entry ) {
//There is no concept of user notifications anymore, so we will need to target notifications based on other criteria,
//such as name or subject
if($notification["name"] == "User Notification - Life Lesson"){
//get upload root for WordPress