Skip to content

Instantly share code, notes, and snippets.

@janzikmund
janzikmund / External Links Target Blank.js
Last active April 21, 2018 09:17
Automatically open external link to new window using target="_blank"
@janzikmund
janzikmund / Cookies - create read delete.js
Last active April 21, 2018 09:18
JS for create, read and delete cookies
createCookie: function(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
},
@janzikmund
janzikmund / WordPress adjust category base.php
Last active April 21, 2018 09:21
WordPress setting for URL permalinks structure
<?php
/**
* Changes WordPress posts URL structure, so that in results in following:
*
* Articles overview: /articles/
* Category overview: /articles/europe
* Article detail: /articles/europe/title
* Tag detail: /articles/tag/work
*
* Requires following settings of Permalinks:
@janzikmund
janzikmund / WordPress gettext filtering.php
Last active April 21, 2018 09:21
WordPress gettext filter
<?php
// custom text translations
add_filter( 'gettext', function( $translated_text, $text, $domain ) {
$translations = array(
'qode' => array(
'view' => 'read more',
),
'wpgmp_google_map' => array(
'Enter address or latitude or longitude or title or city or state or country or postal code here...' => 'Suburb, Town, City'
),
@janzikmund
janzikmund / WordPress Ubuntu font fix quotes.php
Created April 21, 2018 09:26
Fixes Ubuntu font not showing quotes properly
<?php
// replace content filtered entities back, as certain characters are not defined in Ubuntu font
add_filter('the_content', 'sw_replace_quotes_back', 100);
add_filter('wpp_post', 'sw_replace_quotes_back', 100);
add_filter('acf/load_value', 'sw_replace_quotes_back', 100);
add_filter('acf/format_value_for_api', 'sw_replace_quotes_back', 100);
add_filter('the_title', 'sw_replace_quotes_back', 100);
function sw_replace_quotes_back($str) {
$search = array('&#8217;', '’', '&#8220;', '&#8221;', '“', '”');
@janzikmund
janzikmund / WordPress excerpt out of the loop.php
Last active April 21, 2018 09:29
Get post excerpt out of the loop
<?php
// get excerpt out of the loop
function my_excerpt($post_id) {
$post = get_post($post_id);
if ($post->post_excerpt) {
// excerpt exists, return it
return apply_filters('the_excerpt', $the_post->post_excerpt);
} else {
setup_postdata( $post );
@janzikmund
janzikmund / Laravel helper flash messages.php
Last active April 21, 2018 09:40
Laravel helper to output flash messages
<?php
// /app/helpers.php:
function flash($message, $status = 'info') {
session()->flash('flash_message', $message);
session()->flash('flash_message_status', $status);
}
@janzikmund
janzikmund / WordPress remove default image sizes.php
Created April 21, 2018 12:58
WordPress remove default image sizes
<?php
// Remove default image sizes we don't need
add_filter( 'intermediate_image_sizes_advanced', function ( $sizes ) {
unset( $sizes['thumbnail']); // 150px
unset( $sizes['medium']); // 300px
unset( $sizes['large']); // 1024px
unset( $sizes['medium_large']); // 768px
return $sizes;
});
@janzikmund
janzikmund / WordPress JS scrolling within pages.js
Last active April 21, 2018 13:30
WordPress JS scrolling within pages
jQuery(function($) {
// get vertical offset of element by selector
var getElOffset = function(selector) {
var offset;
if(selector === '#top') {
return 0;
} else {
offset = $(selector).offset();
if(typeof offset === 'undefined') return false;
@janzikmund
janzikmund / WordPress responsive images with SRCSET.php
Created April 21, 2018 14:07
WordPress responsive images with SRCSET
<?php
// from ACF
if($image = get_field('photo')): ?>
<?php ps_responsive_image($image, 'large', '(min-width: 1160px) 173px, (min-width: 1024px) calc(25vw - 117px), (min-width: 768px) calc(25vw - 72px), 150px'); ?>
<?php endif
// featured image as variable
if (has_post_thumbnail( get_the_id() ) ) {
$profile_image_html = ps_get_responsive_image(get_post_thumbnail_id( get_the_id() ), 'team-profile', '(min-width: 768px) 90px, 140px');
}