Skip to content

Instantly share code, notes, and snippets.

View kuldeepdaftary's full-sized avatar
🎯
Focusing

Kuldeep Daftary kuldeepdaftary

🎯
Focusing
  • London
View GitHub Profile
@kuldeepdaftary
kuldeepdaftary / es7-async-await.js
Created May 21, 2017 20:03 — forked from msmfsd/es7-async-await.js
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
margin: 0;
}
path.line {
@kuldeepdaftary
kuldeepdaftary / gist:5804047
Created June 18, 2013 09:40
Wordpress intelligent Excerpt. Following function will create an excerpt from content where first sentence ends (with period) or if first sentence is too long it will only show number of characters defined in the function. in following case it'll show 200 characters.
<?php
// Variable & intelligent excerpt length.
function print_excerpt($length) { // Max excerpt length. Length is set in characters
global $post;
$text = $post->post_excerpt;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
}
@kuldeepdaftary
kuldeepdaftary / gist:5803978
Last active December 18, 2015 15:19
Remove P tags around images in wordpress
<?php
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
?>
@kuldeepdaftary
kuldeepdaftary / gist:5803971
Last active December 18, 2015 15:19
Decide when you want to apply the auto paragraph Wordpress
<?php
add_filter('the_content','my_custom_formatting');
function my_custom_formatting($content){
if((get_post_type()=='trend-story') || (get_post_type()=='fashion-story') || (get_post_type()=='how-to-wear-it'))
return $content; //no autop
else
return wpautop($content);
}
?>