Skip to content

Instantly share code, notes, and snippets.

@dededey
dededey / nth-child.less
Created September 15, 2015 12:41
looping for iteration creat nth child x for background color
.loopingClass (@index) when (@index > 0) {
.single-day:nth-child(@{index}){ background-color: darken(#96bbdd,@index*4) ;}
.loopingClass(@index - 1);
}
// end the loop when index is 0
.loopingClass (0) {}
// "call" the loopingClass the first time with highest value
.loopingClass (@iterations);
function add_custom_types_to_tax( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
// Get all your post types
$post_types = get_post_types();
// $post_types = array( 'post', 'your_custom_type' );
$query->set( 'post_type', $post_types );
return $query;
}
@dededey
dededey / array_unique_mod.php
Created November 10, 2015 10:18
select distinct values in array by key
<?php
foreach ($network as $net) :
$hash = $net['current_tax'];
$continent_unique[$hash] = $net;
endforeach;
?>
@dededey
dededey / last_post.php
Created November 16, 2015 11:12
This function returns the total amount of posts available after the current post.
// This function returns the total amount of posts available after the current post.
function more_posts() {
global $wp_query;
return $wp_query->current_post + 1 < $wp_query->post_count;
}
@dededey
dededey / drag_update.php
Created November 23, 2015 14:40
flexslider update DRAG
// DRAG:
if (slider.vars.drag) {
slider.bind('udragstart.udrag', function(event) {
event.preventDefault();
var target = (event.px_delta_x < 0) ? slider.getTarget('next') : slider.getTarget('prev');
slider.flexAnimate(target, slider.vars.pauseOnAction);
});
}
@dededey
dededey / svg.php
Created November 25, 2015 14:45
add svg support to wordpress uploader
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
function fix_svg_thumb_display() {
echo '
td.media-icon img[src$=".svg"], img[src$=".svg"].attachment-post-thumbnail {
@dededey
dededey / rewrite_url_video.php
Created January 26, 2016 14:03
rewrite the youtube vimeo url
// function to rewrite the VIMEO YOUTUBE URL
function mod_url($url){
$yt = strpos($url, 'youtube');
$vim = strpos($url, 'vimeo');
if($yt):
$url = str_replace("watch?v=","v/",$url);
endif;
if($vim):
$url = str_replace("vimeo.com","player.vimeo.com/video",$url);
@dededey
dededey / prev_next_posts.php
Created February 2, 2016 14:38
prev next arrows
<?php
$right_arrow = "<img src=\"".$dir."/images/news/next_news.svg\" />";
next_post_link('%link',$right_arrow);
?>
@dededey
dededey / attachment_url.php
Created February 23, 2016 11:45
save attachment url in wp media
function _save_attachment_url($post, $attachment) {
if ( isset($attachment['url']) )
update_post_meta( $post['ID'], '_wp_attachment_url', esc_url_raw($attachment['url']) );
return $post;
}
add_filter('attachment_fields_to_save', '_save_attachment_url', 10, 2);
function _replace_attachment_url($form_fields, $post) {
if ( isset($form_fields['url']['html']) ) {
$url = get_post_meta( $post->ID, '_wp_attachment_url', true );
if ( ! empty($url) )
@dededey
dededey / password.php
Created March 31, 2016 15:22
password salt generator and has
$salt = uniqid(mt_rand(), true);
function getSaltedHash($password, $salt) {
$hash = $password . $salt;
for ($i = 0; $i < 50; $i++) {
$hash = hash('sha512', $password . $hash . $salt);
}
return $hash;
}