Skip to content

Instantly share code, notes, and snippets.

Avatar

pramod pandey pramod1988

View GitHub Profile
View helpers.php
<?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 Mar 29, 2017
Add script in footer in wordpress
View functions.php
function myscript() {
?>
<script type="text/javascript">
if ( undefined !== window.jQuery ) {
// Jquery code goes here
}
</script>
<?php
}
@pramod1988
pramod1988 / functions.php
Last active Mar 29, 2017
Wordpress Child theme add css and js
View functions.php
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 Mar 29, 2017
Add & save Metabox in wordpress post to enhance functionality
View functions.php
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 Jan 14, 2017
Add Open graph meta tags and twitter card tags to wordpress theme functions.php
View 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) {
View .htaccess
#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
You can’t perform that action at this time.