Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / External Links Target Blank.js
Last active April 21, 2018 09:17
Automatically open external link to new window using target="_blank"
@janzikmund
janzikmund / Magento transfer storeview to default.php
Last active November 12, 2021 22:08
Move / merge all product attributes from Magento storeview level to Default Scope and erases them on storeview level so Default takes priority everywhere
<?php
/* Script to migrate all data from storeview 1 to Default Scope (storeview 0)
@author - Jan Zikmund
*/
$store_from = 1;
$store_to = 0;
$tables = array(
'catalog_product_entity_varchar',
'catalog_product_entity_text',
@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 add sitemap link to robots.txt.php
Last active May 6, 2020 22:01
WordPress add sitemap_index.xml link to robots.txt
@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;
});