Skip to content

Instantly share code, notes, and snippets.

View al5dy's full-sized avatar

Anton Lokotkov al5dy

View GitHub Profile
@al5dy
al5dy / settings.php
Created December 26, 2016 09:00
Универсальное добавление класса "table" в <table>
if ( false !== strpos( $content, '<table' ) ) {
$rep = preg_replace('~<table\K(?:[^>]*?\K(\s?)class="([^"]*)")?~', ' class="$2$1table"', $rep);
}
@al5dy
al5dy / functions.php
Created December 18, 2016 08:10
Автоматическое отображение миниатюры вверху страницы
add_action( 'genesis_entry_content', 'featured_post_image', 8 );
function featured_post_image() {
if ( !is_singular( array( 'post', 'page' ) )) return;
the_post_thumbnail('featured');
}
@al5dy
al5dy / backup.php
Created November 14, 2016 06:14 — forked from menzerath/backup.php
PHP: Recursively Backup Files & Folders to ZIP-File
<?php
/*
* PHP: Recursively Backup Files & Folders to ZIP-File
* (c) 2012-2014: Marvin Menzerath - http://menzerath.eu
*/
// Make sure the script can handle large folders/files
ini_set('max_execution_time', 600);
ini_set('memory_limit','1024M');
@al5dy
al5dy / promobox.php
Created September 26, 2016 13:52
Проверяем, является ли текущая страница блоговой или нет.
function is_page_for_posts() {
$result = false;
if ( is_home() && ! is_front_page() ) {
$page = get_queried_object();
$result = ! is_null( $page ) && $page->ID == get_option( 'page_for_posts' );
}
return $result;
@al5dy
al5dy / sidebar.php
Created August 15, 2016 18:24
Добавление элемента в опреденное место в ассоциативном массиве php.
$array = array(
'zero' => '0',
'one' => '1',
'two' => '2',
'three' => '3',
);
$res = array_slice($array, 0, 3, true) +
array("my_key" => "my_value") +
array_slice($array, 3, count($array) - 1, true) ;
print_r($res);
@al5dy
al5dy / bootstrap-point.js
Created August 11, 2016 06:10
Легкий способ найти текущий тип Bootstrap экрана.
findPoint : function () {
var envs = ['xs', 'sm', 'md', 'lg'];
$el = $('<div>');
$el.appendTo($('body'));
for (var i = envs.length - 1; i >= 0; i--) {
var env = envs[i];
$el.addClass('hidden-'+env);
@al5dy
al5dy / admin.js
Created August 11, 2016 06:05
Выделяем всю область контента при одном нажатии.
$(document).on('click', '.multitext', function () {
var range = document.createRange();
range.selectNodeContents(this);
window.getSelection().addRange(range);
});
@al5dy
al5dy / functions.php
Created July 14, 2016 19:07
Yoast SEO - убираем теги <image:image> для Yandex
function yoast_clear_sitemap( $output, $url ) {
$timezone = new WPSEO_Sitemap_Timezone();
$date = null;
if ( ! empty( $url['mod'] ) ) {
$date = $timezone->format_date( $url['mod'] );
}
@al5dy
al5dy / custom.js
Created July 8, 2016 08:59
"Размазываем" фоновое видео в зависимости от соотношения сторон
vimeoSettings : function () {
var wa = 16, // Соотношение сторон
ha = 9, // Соотношение сторон
$videoBlock = $('.vimeo-video'), // Блок внутри которого лежит iframe
od = $videoBlock.width()/$videoBlock.height(),
vd = wa/ha,
nvh = (od/vd)*100,
nvw = (vd/od)*100;
if (od>vd)
@al5dy
al5dy / woocommerce.php
Last active July 7, 2016 07:47
Получить ID из любого YouTube видео URL (PHP)
function get_youtube_id( $url = '' ) {
$url = preg_replace('~https?://(?:[0-9A-Z-]+\.)?(?:youtu\.be/| youtube(?:-nocookie)?\.com\S*?[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:[\'"][^<>]*>| </a>))[?=&+%\w.-]*~ix', '$1', $url);
return $url;
}