Skip to content

Instantly share code, notes, and snippets.

View bepatrickdavid's full-sized avatar

bepatrickdavid bepatrickdavid

View GitHub Profile
@bepatrickdavid
bepatrickdavid / gist:0c5432b1b3b362913d71
Last active September 28, 2015 10:15
WP: htaccess redirect reindirizzamento page in base languages in base alla lingua
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^/?$ http://www.zendergroup.com/en/ [R,NC,L]
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^/?$ http://www.zendergroup.com/de/ [R,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
@bepatrickdavid
bepatrickdavid / gist:14fcbc4651b020f28173
Created September 28, 2015 10:54
jQUERY: click every x second
var interval = null;
jQuery(function(){
interval = setInterval(callFunc, 5000);
});
function callFunc(){
jQuery('.slick-next').trigger('click');
}
@bepatrickdavid
bepatrickdavid / script.js
Created October 13, 2015 08:47
Magnific Popup: img link and a link
$('.one-slide').each(function() { // the containers for all your galleries
$(this).magnificPopup({
delegate: 'a', // the selector for gallery item
type: 'image',
gallery: {
enabled:true
}
});
});
@bepatrickdavid
bepatrickdavid / gist:4c4d49943756e8a56392
Created November 18, 2015 08:47
Calculate distance between two points on a globe
//PHP
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
$earth_radius = 6371;
$dLat = deg2rad($latitude2 - $latitude1);
$dLon = deg2rad($longitude2 - $longitude1);
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon/2) * sin($dLon/2);
$c = 2 * asin(sqrt($a));
$d = $earth_radius * $c;
@bepatrickdavid
bepatrickdavid / gist:30b8ec65d6450fe03caf
Created February 5, 2016 07:54
htaccess: Remove query string from static resources
//wordpress function.php
function _remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
@bepatrickdavid
bepatrickdavid / gist:9ba398d27ca7c9b7ae84
Created March 2, 2016 09:57
jQuery: nascondere tastiera ios hide keyboard
//se si preme enter
$(document).on("keyup", "input", function(event) {
// If enter is pressed then hide keyboard.
if(event.keyCode == 13) {
$("input").blur();
}
});
//nasconde
$("input").blur();
//esempio
$("#findstore").autocomplete({
minLength:3,
source: function(request, response) {
var matches = $.map( availableTags, function(tag) {
if ( tag.toUpperCase().indexOf(request.term.toUpperCase()) === 0 ) {
return tag;
}
});
@bepatrickdavid
bepatrickdavid / gist:34a7d7808b9a389cbb1b
Created March 7, 2016 15:35
WordPress Asking for Local FTP Credentials on XAMPP
cd /Applications/XAMPP/xamppfiles/
This will get you to the XAMPP file directory. Now we’re going to modify your htdocs directory:
sudo chown -R daemon htdocs
Enter your root password when prompted, then finish it out with a chmod call:
sudo chmod -R g+w htdocs
And you’re done!
@bepatrickdavid
bepatrickdavid / funtions.php
Created April 1, 2016 08:09
WP: Add character counter excerpt Riassunto limitazione caratteri
function excerpt_count_js(){
if ('page' != get_post_type()) {
echo '<script>jQuery(document).ready(function(){
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:12px;right:34px;color:#666;\"><small>Excerpt length: </small><span id=\"excerpt_counter\"></span><span style=\"font-weight:bold; padding-left:7px;\">/ 500</span><small><span style=\"font-weight:bold; padding-left:7px;\">character(s).</span></small></div>");
jQuery("span#excerpt_counter").text(jQuery("#excerpt").val().length);
jQuery("#excerpt").keyup( function() {
if(jQuery(this).val().length > 500){
jQuery(this).val(jQuery(this).val().substr(0, 500));
@bepatrickdavid
bepatrickdavid / template.php
Created April 14, 2016 08:00
WP: Pagination custom post types
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$the_query = new WP_Query( array (
'post_type' => 'offer',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged
) );