Skip to content

Instantly share code, notes, and snippets.

View kostasx's full-sized avatar
💭
Uncaught ReferenceError

Kostas Minaidis kostasx

💭
Uncaught ReferenceError
View GitHub Profile
@kostasx
kostasx / functions.php
Created January 3, 2019 16:15
WordPress Localized Scripts: Pass PHP data to JavaScript - The PHP code.
<?php
// Place this code in your child theme's functions.php file
function myprefix_enqueue_scripts() {
wp_enqueue_script(
'custom-script',
get_stylesheet_directory_uri() . '/js/custom.js'
);
wp_localize_script( 'custom-script', 'php_data', array(
@kostasx
kostasx / paste-ga-alternative-async-tracking-snippet.js
Last active December 20, 2018 15:38
Google Analytics JavaScript async Snippet to paste on the GA input field
(function(){
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
var s = document.createElement('script');
s.setAttribute('async', true);
s.setAttribute('src', 'https://www.google-analytics.com/analytics.js');
var $head = document.getElementsByTagName('head');
@kostasx
kostasx / paste-ga-javascript-tracking-snippet.js
Last active December 20, 2018 15:30
Google Analytics JavaScript Snippet to paste on the GA input field
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
@kostasx
kostasx / ga-alternative-async-tracking-snippet.js
Created December 20, 2018 15:19
Google Analytics Alternative async tracking snippet
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
@kostasx
kostasx / ga-javascript-tracking-snippet.js
Created December 20, 2018 15:17
Google Analytics JavaScript tracking snippet
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
@kostasx
kostasx / Multiple-Elements-Single-Handler.js
Last active November 15, 2018 22:02
JavaScript: Use a single function to handle an event on multiple elements
let buttonOne = document.querySelector(".button-one");
let buttonTwo = document.querySelector(".button-two");
function handleClick(event){
console.log( "Event " + event.type + " on " + event.target );
}
buttonOne.addEventListener( "click", handleClick );
buttonTwo.addEventListener( "click", handleClick );
@kostasx
kostasx / index.html
Created October 17, 2018 19:53 — forked from exarcheia-web/index.html
LESSON 1-2 Html Basic Essential Markup
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Example page</title>
</head>
<body>
<h1>Hello world</h1>
<p>Lorem ipsum dolor sit amet, consectetur.</p>
@kostasx
kostasx / html-boilerplate
Created October 17, 2018 19:52 — forked from exarcheia-web/html-boilerplate
LESSON 2 Standard html5 boilerplate - 2013
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example page</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="favicon.ico" rel="shortcut icon">
<link href="apple-touch-icon.png" rel="apple-touch-icon">
@kostasx
kostasx / example-html
Created October 17, 2018 19:51 — forked from exarcheia-web/example-html
LESSON 2 An example of a typical html5 page structure with commonly used tags
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example page</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
function parseVideo (url) {
// - Supported YouTube URL formats:
// - http://www.youtube.com/watch?v=My2FRPA3Gf8
// - http://youtu.be/My2FRPA3Gf8
// - https://youtube.googleapis.com/v/My2FRPA3Gf8
// - Supported Vimeo URL formats:
// - http://vimeo.com/25451551
// - http://player.vimeo.com/video/25451551
// - Also supports relative URLs:
// - //player.vimeo.com/video/25451551