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 / eventloop-afdemp-4-2-class-exercise-11.markdown
Created March 1, 2019 08:49
EventLoop | AfDEMP 4.2 Class Exercise 11
@kostasx
kostasx / eventloop-afdemp-4-2-class-exercise-10.markdown
Created February 28, 2019 22:26
EventLoop | AfDEMP 4.2 Class Exercise 10
@kostasx
kostasx / web-scraping-titles.js
Created January 8, 2019 22:27
Web Scraping for the lazy developer [ YouTube: https://youtu.be/yB_oh7WgRU8 ]
let result = Array.from( document.querySelectorAll("h3.section-title") )
.map( (title) => title.textContent.trim()).join("\n");
copy( result );
@kostasx
kostasx / insert-headers-and-footers-conditional.html
Last active March 17, 2020 06:03
Execute JavaScript on Specific Posts or Pages using the Insert Headers and Footers WordPress Plugin
<!-- Insert in the Footer Area of the Plugin: -->
<script>
if ( document.querySelector("body.postid-NUM") ){
// Code to be executed on the selected Post or Page with ID NUM goes here...
// Replace NUM with the ID Number of your Post or Page
}
</script>
@kostasx
kostasx / custom.js
Created January 3, 2019 16:17
WordPress Localized Scripts: Pass PHP data to JavaScript - The JavaScript code.
// Paste this code in a file inside your child theme's folder: /js/custom.js
jQuery(function($) {
alert( php_data.message );
});
@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');