Skip to content

Instantly share code, notes, and snippets.

Avatar

Ivan Dorić ivandoric

View GitHub Profile
@ivandoric
ivandoric / gist:11211773
Last active Aug 29, 2015
shell: Change all directories to 755 and all files to 644
View gist:11211773
find . -type d -print0 | xargs -0 chmod 0775 # For directories
find . -type f -print0 | xargs -0 chmod 0664 # For files
@ivandoric
ivandoric / gist:11219200
Created Apr 23, 2014
jQuery: Vertical align elements
View gist:11219200
(function (jQuery) {
// VERTICALLY ALIGN FUNCTION
jQuery.fn.vAlign = function() {
return this.each(function(i){
var ah = jQuery(this).height();
var ph = jQuery(this).parent().height();
var mh = Math.ceil((ph-ah) / 2);
jQuery(this).css('padding-top', mh);
});
};
@ivandoric
ivandoric / gist:11215366
Created Apr 23, 2014
wordpress: Add aditional text to wp_nav_menu using walker object
View gist:11215366
/* functions.php */
<?php
class description_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
@ivandoric
ivandoric / gist:11219463
Created Apr 23, 2014
wordpress: Multiple excerpt lenghts in wordpress
View gist:11219463
<?php
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
@ivandoric
ivandoric / gist:11215625
Created Apr 23, 2014
drupal: Get author user name from $uid
View gist:11215625
<?php
$username = $node->name;
print $username;
?>
@ivandoric
ivandoric / gist:11215120
Created Apr 23, 2014
wordpress: Remove width/height from featured images
View gist:11215120
<?php
/* Remove width/height from featured images */
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
function remove_thumbnail_dimensions( $html ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
@ivandoric
ivandoric / gist:11220757
Created Apr 23, 2014
wordpress: Remove styling for WP gallery
View gist:11220757
<?php
add_filter('gallery_style',
create_function(
'$css',
'return preg_replace("#<style type=\'text/css\'>(.*?)</style>#s", "", $css);'
)
);
@ivandoric
ivandoric / gist:11215642
Created Apr 23, 2014
drupal: If content type do something
View gist:11215642
<?php if($node->type=='node-type-name'){ ?>
@ivandoric
ivandoric / gist:11215395
Created Apr 23, 2014
drupal: Add block to node
View gist:11215395
<?php
$block = block_load('module_name', 'block_name');
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
print $output;
//module_name is the name of module that outputs the block, eg. webform
//block_name is the name of the block, you can find it out by hovering on configure link on block admin page, eg. client-block-19
@ivandoric
ivandoric / gist:11219242
Created Apr 23, 2014
woocommerce: Control number of columns in Woocommerce catalog
View gist:11219242
<?php
//Just put it in functions.php
/* Number of columns in Woocommerce Loop */
global $woocommerce_loop;
$woocommerce_loop['columns'] = 2;