Skip to content

Instantly share code, notes, and snippets.

View seredniy's full-sized avatar
🏠
Working from home

Anton Serednii seredniy

🏠
Working from home
View GitHub Profile
@seredniy
seredniy / terminal.sh
Created April 22, 2021 13:01
Create symlink for folder in Windows 10
mklink /j "C:\laragon\www\test-multi\wp-content\plugins" "C:\laragon\www\test\wp-content\plugins"
First folder will be a link to the second folder.
@seredniy
seredniy / functions.php
Created April 21, 2021 13:17
Get WordPress site domain
$site_domain = wp_parse_url( site_url(), PHP_URL_HOST ); // site.com
// canonical для страниц пагинации
function change_yoast_canonical( $canonical ) {
if ( is_paged() AND is_archive() )
$canonical = preg_replace('/\/page\/.*/', '', $canonical);
return $canonical;
}
add_filter( 'wpseo_canonical', 'change_yoast_canonical', 10, 1 );
@seredniy
seredniy / wp-image-placeholder.php
Created October 20, 2019 17:41 — forked from mihdan/wp-image-placeholder.php
Заменяет битые ссылки на кратинки в WordPress на заглушки. Удобно, например на тестовом сайте, чтобы не переносить фотки с боевого.
<?php
/**
* Plugin Name: Mihdan: Image Placeholder
*/
namespace Mihdan_Image_Placeholder;
$images = array(
// Обычные
'https://placeimg.com/640/480/animals',
@seredniy
seredniy / index.php
Created June 18, 2019 13:54 — forked from ciorici/index.php
Featured Products Loop in WooCommerce 3.0
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 12,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
PHPSTORM:
settings/terminal
shell path: C:\Windows\System32\bash.exe
@seredniy
seredniy / functions.php
Last active March 25, 2023 10:16
Wordpress image helper with alt, title, classes and kama thumbnail
<?php
/**
* Display image with all attributes
* Function uses Kama Thumbnail plugin to crope images
*
* @param int $id attachment id
* @param string $kama_args string of arguments for kama_thumbnail
* @param string $classes list of classes separated by space
* @param string $alt custom alt for image
* @param string $title custom title for image
@seredniy
seredniy / wc-redirect-after-add-to-cart.php
Created August 17, 2018 08:46 — forked from JeroenSormani/wc-redirect-after-add-to-cart.php
WooCommerce redirect after add to cart
/**
* Redirect to checkout at add-to-cart action.
*/
function redirect_to_checkout() {
return WC()->cart->get_checkout_url();
}
add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_to_checkout' );
------------------------------------
@seredniy
seredniy / wpcf7_modal_right_answer.php
Created July 13, 2018 11:30 — forked from campusboy87/wpcf7_modal_invalid.php
Displays a message about the successful submission of the form in a modal window for the Contact Form 7 plugin
<?php
/**
* Plugin Name: CF7 Modal Right Answer
* Plugin URI: https://gist.github.com/campusboy87/a056c288c99feee70058ed24cee805ad
* Author: Campusboy (wp-plus)
* Author URI: https://www.youtube.com/wp-plus
*/
add_action( 'wp_enqueue_scripts', 'wpcf7_modal_right_answer_js' );
add_action( 'wp_footer', 'wpcf7_modal_right_answer_js_inline', 999 );
@seredniy
seredniy / request.php
Created June 26, 2018 15:01 — forked from campusboy87/request.php
Имитирует функционал "Отображать на статической странице список записей".
<?php
add_filter( 'request', function ( $query_vars ) {
if ( isset( $query_vars['pagename'] ) && $query_vars['pagename'] === 'all-articles' ) {
add_filter( "pre_option_page_for_posts", function () {
return 484; // ID нужной страницы
} );
}
return $query_vars;