Skip to content

Instantly share code, notes, and snippets.

View Korveld's full-sized avatar

Kirill Titov Korveld

View GitHub Profile
@Korveld
Korveld / check data type of any variable in jQuery
Created July 9, 2022 08:52
check data type of any variable in jQuery
JQuery.type(object);
@Korveld
Korveld / Wordpress redirection get all urls except a couple
Created July 8, 2022 12:20
Wordpress redirection get all urls except a couple
^/lt/blog/(?!some-slug-one|some-slug-two)(.*)
@Korveld
Korveld / yoast_seo_canonical_change_woocom_shop.php
Created February 28, 2022 13:35 — forked from amboutwe/yoast_seo_canonical_change_woocom_shop.php
Code snippets for the Yoast SEO canonical output
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Change the canonical link for the shop page
* Credit: Scott Weiss of somethumb.com
* Last Tested: Jan 25 2017 using Yoast SEO 6.0 on WordPress 4.9.1
*/
function yoast_seo_canonical_change_woocom_shop( $canonical ) {
if ( !is_shop() ) {
@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
@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 / 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 / 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 / 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 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 / 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;
}