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 / list-categories.php
Last active April 24, 2017 14:47
List WordPress parent and child categories, if parent have childern display dropdown othervise clickable link.
<ul class="sidebar-menu">
<?php
$parent_terms = get_terms( 'product_cat', array( 'hide_empty' => false, 'parent' => 0 ) );
foreach( $parent_terms as $parent_term ) {
// display top level term name
$child_terms = get_terms( 'product_cat', array( 'hide_empty' => false, 'parent' => $parent_term->term_id ) );
?>
<li class="cat-item <?php if ($child_terms) { echo "have-children"; } ?>"><a href="<?php echo get_term_link($parent_term); ?>"><?php echo $parent_term->name; ?></a>
<?php if ($child_terms) : ?>
<ul class="children">
@nikola0203
nikola0203 / repeater-loop-even-number.php
Last active March 6, 2018 11:45
Repeater field ACF count in while loop even and odd number and display in different order.
<?php
if( have_rows('repeater_field') ):
$postCount = 1;
while( have_rows('repeater_field') ) : the_row(); ?>
<?php
$repeater_sub_field_1 = get_sub_field('repeater_sub_field_1');
$repeater_sub_field_2 = get_sub_field('repeater_sub_field_2');
$repeater_sub_field_3 = get_sub_field('repeater_sub_field_3');
@nikola0203
nikola0203 / functions.php
Created July 13, 2017 08:23 — forked from gagimilicevic/functions.php
Detect RTL on website
function wp_is_rtl( $locale = '' ) {
static $rtl_locales = array(
'ar' => 'Arabic',
'ary' => 'Moroccan Arabic',
'azb' => 'South Azerbaijani',
'fa_IR' => 'Persian',
'haz' => 'Hazaragi',
'he_IL' => 'Hebrew',
'ps' => 'Pashto',
'ug_CN' => 'Uighur',
@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 : {
@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 / 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,
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 / 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)
@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 / 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 ) {