Skip to content

Instantly share code, notes, and snippets.

View nikola0203's full-sized avatar

Nikola Milosevic nikola0203

  • SEO 1 Click
  • Belgrade, Serbia
View GitHub Profile
@nikola0203
nikola0203 / gist:df8773ad0e91aa42c4bc06265750d0c7
Created February 28, 2023 13:54
Enable Strict Transport Security in Apache .htaccess
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
</IfModule>
@nikola0203
nikola0203 / acf-image
Last active March 2, 2022 11:35
ACF image with lazy load classes
/**
* ACF image
*
* @param array $image_array
* @param string $size
* @param string $css_class
* @return html
*/
public static function acfImage( $image_array, $size = 'thumbnail', $css_class = '' )
{
import 'swiper/css'
import 'swiper/css/navigation'
import Swiper, { Navigation, Pagination } from 'swiper';
$(".swiper-container").each(function(index, element){
$(this).addClass("swiper-container-" + index);
$(this).find(".swiper-button-prev").addClass("swiper-button-prev-" + index);
$(this).find(".swiper-button-next").addClass("swiper-button-next-" + index);
new Swiper(".swiper-container-" + index, {
@nikola0203
nikola0203 / minify-css.php
Last active February 18, 2020 09:35
Minify CSS with PHP
// Get CSS
$css = get_option( 'css' );
// Remove comments
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
// Remove space after colons
$buffer = str_replace(': ', ':', $buffer);
// Remove whitespace
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
// Display CSS
if ( $buffer ) {
@nikola0203
nikola0203 / class-wp-bootstrap-navwalker.php
Created May 29, 2019 10:38
Parent link clickable in Bootstrap with Wordpress NavWalker
// BEFORE
// On line 185:
$atts['href'] = '#';
// On line 186:
$atts['data-toggle'] = 'dropdown';
// AFTER
// On line 185:
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
// On line 186:
@nikola0203
nikola0203 / readme.md
Created April 25, 2019 08:18 — forked from brunoleles/readme.md
Gulp Watch Fails with "Error: watch ... ENOSPC"

gulp watch fails with error: Error: watch ... ENOSPC

Stacktrace:

[13:58:28] Starting 'watch'...
[13:58:28] 'watch' errored after 22 ms
[13:58:28] Error: watch /.../resources/assets/images/ ENOSPC
    at exports._errnoException (util.js:1023:11)
    at FSWatcher.start (fs.js:1306:19)
 at Object.fs.watch (fs.js:1331:11)
function PREFIX_lazy_load_images(image_selector) {
var lazyImages = [].slice.call(document.querySelectorAll(image_selector));
if ("IntersectionObserver" in window && "IntersectionObserverEntry" in window && "intersectionRatio" in window.IntersectionObserverEntry.prototype) {
let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
let lazyImage = entry.target;
lazyImage.src = lazyImage.dataset.src;
@nikola0203
nikola0203 / wc_functions.php
Last active March 6, 2018 11:45
WooCommerce Customer/Order XML Export Suite - change root element of XML document.
// Change first letter of XML tag <Orders> to lowercase.
function custom_xml_root_element( $export_type ) {
return lcfirst( $export_type );
}
add_filter( 'wc_customer_order_xml_export_suite_xml_root_element', 'custom_xml_root_element', 10, 1 );
// Change <Order> tage name.
function custom_order_format_tag_name( $orders_format, $orders ) {
$orders_format = array(
'order' => $orders,
@nikola0203
nikola0203 / archive.php
Created October 20, 2017 18:58
Dynamic category filter
<?php $category = get_the_category(); ?>
<div class="col-md-6 filter <?php echo esc_attr( $category[0]->slug ); ?>">
// Content
</div>
@nikola0203
nikola0203 / ajax.js
Created October 7, 2017 10:31
Wordpress, AJAX call, Bootsrap modal popup. AJAX function to retrieve, WooCommerce single product page, through the Bootstrap modal popup.
jQuery(document).ready(function($){
// Quick view ajax function on products page
$('.quick-view-link, .quick-view-button').on('click', function() {
var post_id = $(this).data('id');
$.ajax({
url : modal_ajax.url,
type : 'post',
data : {