Skip to content

Instantly share code, notes, and snippets.

@kmaroff
kmaroff / sass.sass
Last active December 9, 2021 18:22
$desktop-widths: #{'screen and (min-width : 1170px)'}
$notebook-widths: #{'screen and (min-width : 992px)'}
$tablet-widths: #{'screen and (min-width : 768px)'}
$mobile-widths: #{'screen and (min-width : 480px)'}
/**
* Function to get post ID By slug
* Usage:
* get_id_by_slug('any-page-slug','any-post-type');
*/
function get_id_by_slug($page_slug, $slug_page_type = 'page') {
$find_page = get_page_by_path($page_slug, OBJECT, $slug_page_type);
if ($find_page) {
return $find_page->ID;
add_action( 'pre_get_posts', 'custom_pagesize');
function custom_pagesize( $query ) {
if( is_admin() || ! $query->is_main_query() )
return;
if ( is_post_type_archive('portfolio_pods') ) {
$query->set( 'posts_per_page', 9999 );
return;
add_action('pre_get_posts', 'hwl_home_pagesize', 1 );
function hwl_home_pagesize( $query ) {
// Выходим, если это админ-панель или не основной запрос.
if( is_admin() || ! $query->is_main_query() )
return;
if( is_home() ){
// Выводим только 1 пост на главной странице
$query->set( 'posts_per_page', 1 );
}
//1. Для главной страницы магазина устанавливаем любую страницу со слагом shop.
//2. В настройках постоянных ссылок для базы категорий товаров указываем shop, а для товаров выбираем произвольную базу и вписываем туда /shop/%product_cat%/.
//3. Далее, используя сниппет ниже (его можно добавить в functions.php или в mu-plugins), создаём новые правила перенаправления для каждой категории товара, подменяя в ссылках на категорию /product-category/ на /shop/.
//4. В самом конце: зайдите на страницу Настройки -> Постоянные ссылки для сброса правил перенаправлений.
<?php
/**
* Делаем простую и понятную структуру для урлов WooCommerce:
*
* Страница магазина: https://domain.com/shop
add_action( 'wp_head', function(){
if(is_archive('calendar-pods')) {
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
}
}, 0);
// Целиком
add_action('template_redirect','remove_wpseo');
function remove_wpseo(){
if (is_archive('calendar-pods')) {
global $wpseo_front;
if(defined($wpseo_front)){
remove_action('wp_head',array($wpseo_front,'head'),1);
}
else {
//Если не работает пагинация
add_filter('redirect_canonical', 'my_redirect_canonical', 10, 2);
function my_redirect_canonical($redirect_url, $requested_url) {
$do_redirect = true;
if(preg_match('/page/',$requested_url)){
$do_redirect = false;
}
return $do_redirect;
}
//Добавляем нужный атрибут к ссылкам ведущих к изображениям в статьях. В примере используем fancybox
add_filter('the_content', 'addfancybox');
function addfancybox($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 data-fancybox title="'.$post->post_title.'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
<small>This site is protected by reCAPTCHA and the Google
<a href="https://policies.google.com/privacy">Privacy Policy</a> and
<a href="https://policies.google.com/terms">Terms of Service</a> apply.
</small>
.grecaptcha-badge {
visibility: hidden;
}