Skip to content

Instantly share code, notes, and snippets.

@marko-stimac
marko-stimac / wpml-create-translated-posts.php
Created December 13, 2019 13:14
Create translated posts in WPML
// This is not planned for hierarchical posts
add_action('wp_footer', 'create_wpml_translated_posts');
function create_wpml_translated_posts() {
$post_type = 'post';
$new_language = 'en';
$args = array(
'post_type' => $post_type,
'posts_per_page' => -1
@marko-stimac
marko-stimac / create-project-backup
Last active May 31, 2019 06:50
VPS - Create backup for projects
#!/bin/bash
# Create backup for projects while skipping unimportant folders
TIME=`date +%b-%d-%y`
FILENAME=html-$TIME.tar.gz
SRCDIR=/var/www/html
DESDIR=/mnt/ftp/backups
tar -cpzf $DESDIR/$FILENAME --exclude=**/node_modules/* $SRCDIR
@marko-stimac
marko-stimac / create-database-backup.sh
Last active May 31, 2019 06:49
VPS - Create database backup
#!/bin/bash
# Create backup for all databases
w="$(date +'%d_%m_%Y_%H_%M_%S')"
filename="db_$now".gz
backupfolder="/mnt/ftp/dbbackups/test"
fullpathbackupfile="$backupfolder/$filename"
logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt
echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
@marko-stimac
marko-stimac / .htaccess
Last active May 31, 2019 06:47
Htaccess - redirect old domain pages
# Catch 404
ErrorDocument 404 https://oldsite.com/404
RewriteEngine on
# Single page redirect
Redirect 301 /team.php https://newsite.com/our-team/
# Redirect all query variables with url something like https://oldsite.com/blog-list?p=10 to https://newsite.com/en/ (question mark in the end removes query parameter on new page)
RewriteCond %{QUERY_STRING} ^p=(.*)
@marko-stimac
marko-stimac / .htaccess
Created November 20, 2018 10:17
Htaccess - redirect all to root except folder
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/_skip-this-folder$
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* / [L,R=302]
RewriteCond %{HTTP_HOST} ^www.domain.hr [NC]
RewriteRule ^(.*) https://domain.hr/$1 [L,R=301]
@marko-stimac
marko-stimac / wp-all-import-insert-gallery-shortcode.php
Created July 18, 2018 09:46
Wordpress - insert shortcode for gallery when importing images into posts with WP All Import Pro
@marko-stimac
marko-stimac / a11y-event-handler.js
Last active October 17, 2018 19:32
JS - Accessibility event handler
// Accessibility compliant event handler
// Taken from http://www.karlgroves.com/2014/11/24/ridiculously-easy-trick-for-keyboard-accessibility/
function a11yClick(event) {
if(event.type === 'click'){
return true;
}
else if(event.type === 'keypress') {
var code = event.charCode || event.keyCode;
if((code === 32)|| (code === 13)){
@marko-stimac
marko-stimac / wordpress-get-the-date.php
Created September 24, 2018 09:37
Wordpress - get_the_date() to locale
<?php
if (ICL_LANGUAGE_CODE == 'hr') {
setlocale(LC_TIME, 'hr_HR.UTF-8');
echo strtolower(strftime("%e. %B %Y.", get_post_time('U')));
}
else if (ICL_LANGUAGE_CODE == 'en') {
setlocale(LC_TIME, 'en_US.UTF-8');
echo strftime("%A %e %B %Y", get_post_time('U'));
}
?>
@marko-stimac
marko-stimac / animations.js
Last active September 16, 2018 00:21
JS - Animate methods
jQuery(document).ready(function ($) {
'use strict';
// Add class ('appeared') to each element that should be animated when visible on viewport
// Uses scrollmagic.js
var controller = new ScrollMagic.Controller();
$('.animate').each(function () {
$(this).addClass('disappear');
new ScrollMagic.Scene({
@marko-stimac
marko-stimac / comment-form.php
Created August 26, 2018 13:46
Wordpress - show comments and comment form
<!-- Be sure to allow commenting in Wordpress settings -->
<ol class="commentlist">
<?php
$comments = get_comments(array(
'post_id' => get_the_ID(),
'status' => 'approve'
));
wp_list_comments(array(
'per_page' => 30,