Skip to content

Instantly share code, notes, and snippets.

View Korveld's full-sized avatar

Kirill Titov Korveld

View GitHub Profile
@Korveld
Korveld / Copy text from input field
Created September 8, 2021 13:51
Copy text from input field
$('.profile-gift__copy').on('click', function (e) {
e.preventDefault()
$(this).siblings('.form-control').select()
document.execCommand('copy')
})
@Korveld
Korveld / Display All PHP Errors
Last active September 13, 2021 09:39
Display All PHP Errors
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
error_reporting(E_WARNING);
error_reporting(E_NOTICE);
// source: https://stackify.com/display-php-errors/#:~:text=Quickly%20Show%20All%20PHP%20Errors,1)%3B%20error_reporting(E_ALL)%3B
@Korveld
Korveld / Woocommerce show brand names in product page
Last active September 16, 2021 10:12
Woocommerce show brand names in product page
add_action( 'woocommerce_single_product_summary', 'artlife_add_brand_name_to_product_page', 19 );
function artlife_add_brand_name_to_product_page() {
global $post;
$brands = wp_get_post_terms( $post->ID, 'product_brand', array("fields" => "all") );
foreach( $brands as $brand ) {
echo __( 'Brand', 'pharmacy') . ': ' . $brand->name;
}
}
@Korveld
Korveld / Set Yoast Seo extra scheme
Created September 16, 2021 11:30
Set Yoast Seo extra scheme
add_filter( 'woocommerce_structured_data_product', 'custom_set_extra_schema', 20, 2 );
function custom_set_extra_schema( $schema, $product ) {
$gtin = get_post_meta( $product->get_id(), '_custom_gtin', true );
$schema['gtin13'] = $gtin;
return $schema;
}
@Korveld
Korveld / Add rel="preload" to css and js
Created September 20, 2021 09:45
Add rel="preload" to css and js
function add_rel_preload($html, $handle, $href, $media) {
if (is_admin())
return $html;
$html = <<<EOT
<link rel='preload' as='style' onload="this.onload=null;this.rel='stylesheet'"
id='$handle' href='$href' type='text/css' media='all' />
EOT;
return $html;
}
@Korveld
Korveld / Generate webp images in opencart
Created October 8, 2021 18:01
Generate webp images in opencart
Not all the browsers accept WEBP image format but you can type a code to check if the browser accept WEBP format then you will have to make a new images cache and convert the existing images to webp
on the fir dir catalog/model/tool/image.php add
$image_new_webp = 'cachewebp/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '.webp';
after this
$image_new = 'cache/'
to check if the browser accept image.webp and to create your new images cache in the same file: catalog/model/tool/image.php add this code:
@Korveld
Korveld / Add yoast seo breadcrumb translations to wpml
Created October 19, 2021 11:39
Add yoast seo breadcrumb translations to wpml
WPML -> Settings -> Custom XML Configuration tab
<wpml-config>
<admin-texts>
<key name="wpseo_titles">
<key name="breadcrumbs-404crumb"/>
<key name="breadcrumbs-archiveprefix"/>
<key name="breadcrumbs-home"/>
<key name="breadcrumbs-prefix"/>
<key name="breadcrumbs-searchprefix"/>
@Korveld
Korveld / Woocommerce show top sale products
Created October 28, 2021 06:11
Woocommerce show top sale products
<?php echo do_shortcode('[best_selling_products per_page="12" orderby="popularity" order="DESC"]'); ?>
OR
<?php
$args = array(
'post_type' => 'product',
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
'posts_per_page' => 12,
@Korveld
Korveld / JS Check if Function Exists Before Calling
Created November 26, 2021 14:04
JS Check if Function Exists Before Calling
if (typeof yourFunctionName == 'function') {
yourFunctionName();
}
@Korveld
Korveld / Redirect all pages to non-www and HTTPS in WordPress
Created December 20, 2021 14:55
Redirect all pages to non-www and HTTPS in WordPress
# BEGIN Redirects
RewriteEngine On
# 301 redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# 301 redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# END Redirects