Skip to content

Instantly share code, notes, and snippets.

@deepak-rajpal
deepak-rajpal / wp-social-icons.php
Last active August 18, 2021 14:52
Code to add social icons below WordPress post content using filter
/**
* Add social icons below post title using WordPress filter
* * How to use: You can add following code in functions.php in WordPress theme.
*/
// Use WordPress filter to add custom content below WordPress post
add_filter('the_content', 'tc_social_icons_callback');
function tc_social_icons_callback($content)
{
// Get current page URL
@deepak-rajpal
deepak-rajpal / functions.
Created January 3, 2018 13:44
This snippets will include php file only in custom taxonomies section
/* Required files */
global $pagenow;
if (($pagenow == 'edit-tags.php' || $pagenow == 'term.php') && isset($_GET['taxonomy']) && $_GET['taxonomy'] == 'service_type') {
require_once ( THM_DIR_PATH . '/inc/category-media.php' );
}
@deepak-rajpal
deepak-rajpal / gist:77db31564de76f48fce4e79b0a95125c
Created November 29, 2017 09:18
Image scale down images with css looks blurry - image rendering fix
img{
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
-ms-interpolation-mode: nearest-neighbor;
}
@deepak-rajpal
deepak-rajpal / add-widget-class.js
Created January 6, 2016 14:15
adding specific classes to all widgets except text widget
<script>
// Adding Required classes into all sidebar boxes except text widget
jQuery(document).ready(function(){
// $('body').fontResize();
$('#primary .widget-container:not(.widget_text)').addClass('varnav');
$('#primary .widget-container:not(.widget_text) ul').addClass('ml30 mb5');
$('#primary .widget-container:not(.widget_text) ul li a').addClass('bullettext');
$('#primary .widget-container:not(.widget_text)').append('<div class="varnavFooter"></div>');
$('#secondary .widget-container:not(.widget_text)').addClass('rightbox2');
@deepak-rajpal
deepak-rajpal / fb-share-tips.html
Created December 14, 2015 14:58
fb share tips
To ‘know’ the BEST is an impossibility. You can only predict and measure.
When a brand posts twice a day, those posts only receive 57% of the likes and 78% of the comments per post. The drop-off continues as more posts are made in the day.
Facebook – 2 times per day, seven days a week, 10:08 a.m. and 3:04 p.m.
* Target Your Posts
* Use Photos, But Make Them Original
* Post at Odd Hours
* Cross-Promote With Other Pages
@deepak-rajpal
deepak-rajpal / wp-autop-filter.php
Created November 20, 2015 15:06
WordPress Code snippets shortcodes
<?php
/* Disable auto paragraph - sometimes issue while content formatting with wordpress/ck-editor */
remove_filter ('the_content', 'wpautop');
// remove_filter ('the_content', 'wptexturize');
?>
@deepak-rajpal
deepak-rajpal / wp-cache-feed-time-change.php
Created November 20, 2015 14:48
Change WordPress cache feed time from defalut 12 hours to 30 minutes
<?php
/* By default, WordPress cache feed or rather the cached feed has a lifetime of 43200 seconds, equivalent to 12 hours. */
/* Starts: Change the default feed cache recreation period to 1800 seconds/30 minutes */
function return_cache_recreation( $seconds )
{
return 1800;
}
add_filter( 'wp_feed_cache_transient_lifetime' , 'return_cache_recreation' );
/* Ends: Change the default feed cache recreation period */
@deepak-rajpal
deepak-rajpal / unfiltered-html-mu.php
Created November 20, 2015 14:22
Unfiltered HTML plugin selected code to allow admin/editor js/script etc code in WPMU
<?php
/* To allow unfiltered html for admin and editor */
function um_unfilter_roles() {
// Makes sure $wp_roles is initialized
get_role( 'administrator' );
global $wp_roles;
// Dont use get_role() wrapper, it doesn't work as a one off.
// (get_role does not properly return as reference)
$wp_roles->role_objects['administrator']->add_cap( 'unfiltered_html' );
$wp_roles->role_objects['editor']->add_cap( 'unfiltered_html' );
@deepak-rajpal
deepak-rajpal / wp-empty-search.php
Created November 20, 2015 14:18
WordPress Search Filter
<?php
/* When we search without string/word, it redirects to homepage. Fix it by checking this empty case and set query variable with space " " */
function empty_search_filter( $query_vars ) {
if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
$query_vars['s'] = " ";
}
return $query_vars;
}
add_filter( 'request', 'empty_search_filter' );
?>
@deepak-rajpal
deepak-rajpal / api-web-servies.php
Last active October 3, 2017 00:59
Intro to Web Services - Soap and Rest APIs
Web services
A Web service, in very broad terms, is a method of communication between two applications or electronic devices over the World Wide Web (WWW). Web services are of two kinds: Simple Object Access Protocol (SOAP) and Representational State Transfer (REST).
SOAP
SOAP defines a standard communication protocol (set of rules) specification for XML-based message exchange. SOAP uses different transport protocols, such as HTTP and SMTP. The standard protocol HTTP makes it easier for SOAP model to tunnel across firewalls and proxies without any modifications to the SOAP protocol.
The Web Services Description Language (WSDL) contains and describes the common set of rules to define the messages, bindings, operations and location of the Web service. WSDL is a sort of formal contract to define the interface that the Web service offers.
REST
REST is protocol independent. REST-based implementation is simple compared to SOAP. The service producer and service consumer need to have a common understanding of the