Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dnshulga's full-sized avatar
🌴
On vacation

Dmitry Shulga dnshulga

🌴
On vacation
  • Worldwide
View GitHub Profile
function getYouTubeID($url){
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches);
return $matches[1];
}
@dnshulga
dnshulga / Some time ago [Wordpress]
Last active June 5, 2019 13:33
Output of ".. hours ago". If more than 24 hours (1 day) - prints the date in common format
<?php
$time_diff = human_time_diff( get_the_date('U'), current_time('timestamp') );
if( preg_match('~day|month|year~iu', $time_diff ) )
$date = get_the_date('M d');
else
$date = $time_diff.' '.__('ago', 'project-locatization-name');
?>
<p><?php echo $date ?></p>
@dnshulga
dnshulga / Сustom column from ACF field
Last active June 5, 2019 13:35
Add a custom column from ACF field to taxonomy edit page
<?php
function custom_column_header( $columns ){
$columns['image'] = 'Image';
unset($columns['description']);
return $columns;
}
add_filter( "manage_edit-arts_cat_columns", 'custom_column_header', 10);
function custom_column_content( $value, $column_name, $term_id ){
@dnshulga
dnshulga / Reinitialize slick slider
Last active June 5, 2019 13:35
A possibility to reinitialize slick slider if the variable of slick slider is unvisible in your js file
$('.slick-slider').not('.slick-initialized').slick({
infinite: false,
slidesToShow: 1,
slidesToScroll: 1,
dots: true,
arrows: false,
touchThreshold: 9
});
@dnshulga
dnshulga / Fix counters on section Pages Wordpress
Last active April 19, 2019 11:47
How to fix counters on Pages section after hiding of pages from dashboard Wordpress? Here we go
add_action( 'pre_get_posts' ,'dnshulga_exclude_pages' );
function dnshulga_exclude_pages( $query ) {
if( !is_admin() )
return $query;
global $pagenow;
if( 'edit.php' == $pagenow && ( get_query_var('post_type') && 'page' == get_query_var('post_type') ) )
$query->set( 'post__not_in', array(213, 221) ); //ids of pages to hide
return $query;
function remove_default_woo_image_sizes( $sizes ) {
unset( $sizes[ 'shop_thumbnail' ]);
unset( $sizes[ 'shop_catalog' ]);
unset( $sizes[ 'shop_single' ]);
unset( $sizes[ 'woocommerce_thumbnail' ]);
unset( $sizes[ 'woocommerce_single' ]);
unset( $sizes[ 'woocommerce_gallery_thumbnail' ]);
return $sizes;
}
@dnshulga
dnshulga / Hide ACF totally
Created March 21, 2019 15:05
Hide ACF totally: remove admin menu page, remove gear of ACF from pages, do redirect from ACF admin menu page
<?php
/*Hide ACF Tottally*/
add_filter('acf/settings/show_admin', '__return_false');
function pands_admin_colors() {
echo '<style type="text/css">
h2.hndle.ui-sortable-handle a.acf-hndle-cog { display: none; visibility: hidden }
</style>';
}
add_action('acf/input/admin_head', 'pands_admin_colors');
function disallowed_acf_page() {