Skip to content

Instantly share code, notes, and snippets.

View functions.php
<?php
require_once 'vendor/autoload.php';
use GeoIp2\Database\Reader;
/**
* Returns the visitors IP address.
* @return string
*/
View functions.php
<?php
// functions.php code...
$geoip2_country_code = get_geoip2_country_code( get_visitor_IP() );
if ( $geoip2_country_code == 'HR' ) {
wp_redirect( $lander_URL ); exit;
}
@DomagojGojak
DomagojGojak / functions.php
Last active Aug 24, 2016
GeoIP2 reader initialization
View functions.php
<?php
require_once 'vendor/autoload.php';
use GeoIp2\Database\Reader;
// Instantiate the "GeoIp2" Reader object
$reader = new Reader( get_template_directory() . '/GeoLite2-Country.mmdb' );
// Get country details for 78.134.247.178 IP address
$result = $reader->country( '78.134.247.178' )->country;
View header.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
View functions.php
<?php
// ...
function wpmm_init() {
$location = 'mega_menu';
$css_class = 'has-mega-menu';
$locations = get_nav_menu_locations();
if ( isset( $locations[ $location ] ) ) {
$menu = get_term( $locations[ $location ], 'nav_menu' );
@DomagojGojak
DomagojGojak / functions.php
Last active Apr 12, 2017
Registering the "Mega Menu" menu location.
View functions.php
<?php
// ...
function wpmm_setup() {
register_nav_menus( array(
'mega_menu' => 'Mega Menu'
) );
}
add_action( 'after_setup_theme', 'wpmm_setup' );
View scripts.js
jQuery(function($){
$('img.inflated')
.on('webkitmouseforcewillbegin', function(event){
event.preventDefault();
})
.on('webkitmouseforcechanged', function(event){
$(event.target).css({
width: 200 + event.originalEvent.webkitForce * 30
});
})
View style.css
.balloon { width: 262px; height: 300px; position: absolute; top: 50%; left: 50%; margin: -150px 0 0 -131px; }
.balloon img { width: 200px; margin-left: auto; margin-right: auto; }
.balloon img.inflated, .balloon.pop img.popped { display: block; }
.balloon.pop img.inflated, .balloon img.popped { display: none; }
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Force Touch Demo</title>
<link rel='stylesheet' href='style.css' type='text/css' />
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
</head>
<body>
<div class="container">
View package.json
{
"devDependencies": {
"gulp": "3.9.x",
"gulp-less": "3.x.x"
},
"scripts": {
"build:less": "gulp less"
},
"bin": {
"gulp": "node ./node_modules/gulp/bin/gulp.js"