Skip to content

Instantly share code, notes, and snippets.

View pramod1988's full-sized avatar

pramod pandey pramod1988

View GitHub Profile
<?php
function imageUrl($path, $width = NULL, $height = NULL,$quality=NULL,$crop=NULL) {
 
if(!$width && !$height) {
$url = env(‘IMAGE_URL’) . $path;
} else {
$url = url(‘/’) . ‘/timthumb.php?src=’ . env(‘IMAGE_URL’) . $path;
@pramod1988
pramod1988 / functions.php
Created March 29, 2017 10:49
Add script in footer in wordpress
function myscript() {
?>
<script type="text/javascript">
if ( undefined !== window.jQuery ) {
// Jquery code goes here
}
</script>
<?php
}
@pramod1988
pramod1988 / functions.php
Last active March 29, 2017 10:45
Wordpress Child theme add css and js
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
// Get the theme data
$the_theme = wp_get_theme();
wp_enqueue_style( 'child-understrap-styles', get_stylesheet_directory_uri() . '/css/child-theme.min.css', array(), $the_theme->get( 'Version' ) );
wp_enqueue_script( 'child-understrap-scripts', get_stylesheet_directory_uri() . '/js/child-theme.min.js', array(), $the_theme->get( 'Version' ), true );
}
@pramod1988
pramod1988 / functions.php
Created March 29, 2017 10:41
Add & save Metabox in wordpress post to enhance functionality
add_action( 'add_meta_boxes', 'add_events_metaboxes' );
// Add the Events Meta Boxes
function add_events_metaboxes() {
add_meta_box('wpt_events_location', 'Event Details', 'wpt_events_location', 'post', 'normal', 'high');
}
function wpt_events_location() {
global $post;
// Noncename needed to verify where the data originated
@pramod1988
pramod1988 / functions.php
Created January 14, 2017 08:15
Add Open graph meta tags and twitter card tags to wordpress theme functions.php
<?php
function fb_opengraph() {
global $post;
if(is_single()) {
if(has_post_thumbnail($post->ID)) {
$img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium');
} else {
$img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
}
if($excerpt = $post->post_excerpt) {
#Leverage browser caching
.htaccess code Below :- 
# Set up caching on static resources for 1 year based on Google recommendations
<IfModule mod_expires.c>
ExpiresActive On
<FilesMatch “\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|js|css|gif|jpg|jpeg|png|swf)$”>
ExpiresDefault A29030400
</FilesMatch>
</IfModule>
# Enable gzip compression