Skip to content

Instantly share code, notes, and snippets.

View amilabandara's full-sized avatar

Amila Bandara amilabandara

View GitHub Profile
@amilabandara
amilabandara / ratio.scss
Created April 26, 2023 15:49
Responsive Aspect ration images
.ratio-image {
position: relative;
height: 0;
padding-bottom: 100%;
img {
max-width: 100%;
position: absolute;
top: 0;
bottom: 0;
@amilabandara
amilabandara / progress-slick.scss
Created January 31, 2023 06:01
Add progress bar to each slick slide
@keyframes scale-x-zero-to-max {
0% {
transform: scaleX(0);
}
100% {
transform: scaleX(1);
}
}
@amilabandara
amilabandara / getlinks.js
Created December 16, 2021 10:24
Get all links in webpage
@amilabandara
amilabandara / convertchars.php
Created June 19, 2021 12:09
Convert Wired characters to correct chars ’
/*
If you ever see your characters , specially ' and "" converted to ’ this type of characters, this may help you.
*/
$string = "Buyer’s Agent";
echo iconv ( 'UTF-8', 'macintosh', $string );
@DATABASE@__%Y-%m-%d_%H-%M-%S
@amilabandara
amilabandara / remove_hash.js
Created March 26, 2021 17:13
This code remove the hash (http://url#hash) value from url
history.pushState("", document.title, window.location.pathname + window.location.search);
@amilabandara
amilabandara / stopuserenumeration.php
Created March 1, 2021 03:50
Stop user enumeration wordpress
<?php
if (!is_admin()) {
// default URL format
if (preg_match('/author=([0-9]*)/i', $_SERVER['QUERY_STRING'])) die(); add_filter('redirect_canonical', 'shapeSpace_check_enum', 10, 2);
}
function shapeSpace_check_enum($redirect, $request) {
// permalink URL format
if (preg_match('/\?author=([0-9]*)(\/*)/i', $request)) die(); else return $redirect;
}
@amilabandara
amilabandara / youtube-video-url.php
Last active February 10, 2021 10:28
Get youtube image url from video url
<?php
$url = 'https://www.youtube.com/watch?v=DkxMhdtOnKM';
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match);
$youtube_id = $match[1];
$image_url = 'https://img.youtube.com/vi/'.$youtube_id.'/maxresdefault.jpg';
echo $image_url;
@amilabandara
amilabandara / functions.php
Created January 22, 2021 10:56
Discard spam comments
// Discard spam comments while showing spammer it's processed.
add_filter( 'gpb_enable_honeypot', '__return_true' );
@amilabandara
amilabandara / redirect.php
Created November 12, 2020 03:06
Redirect wordpress parent page to first child page
<?php
/*
Template Name: Redirect To First Child
*/
if (have_posts()) {
while (have_posts()) {
the_post();
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));