Skip to content

Instantly share code, notes, and snippets.

Avatar

Ivan Dorić ivandoric

View GitHub Profile
@ivandoric
ivandoric / gist:11215147
Created Apr 23, 2014
wordpress: Hide editor but leave "Add Media" button on post type
View gist:11215147
<?php
function hide_editor_leave_media_button() {
global $current_screen;
if( $current_screen->post_type == 'ENTER_POST_TYPE_HERE' ) {
$css = '<style type="text/css">';
$css .= '#wp-content-editor-container, #post-status-info, .wp-switch-editor { display: none; }';
$css .= '</style>';
echo $css;
@ivandoric
ivandoric / gist:11220540
Created Apr 23, 2014
wordpress: Print featured image title insted of post title
View gist:11220540
/* Add this to functions.php */
<?php
function pj_featured_img_title() {
global $post;
$pj_thumbnail_id = get_post_thumbnail_id($post->ID);
$pj_thumbnail_image = get_posts(array('p' => $pj_thumbnail_id, 'post_type' => 'attachment', 'post_status' => 'any'));
if ($pj_thumbnail_image && isset($pj_thumbnail_image[0])) {
return $pj_thumbnail_image[0]->post_title;
}
@ivandoric
ivandoric / gist:11215689
Created Apr 23, 2014
wordpress: Title for custom Wordpress pages, that have special loops on them
View gist:11215689
<?php
$post_id = $wp_query->post->ID; // get post ID
?>
<h2><?php echo get_the_title($post_id); ?></h2>
/* If using WPML for translation then */
<h2><?php echo get_the_title(icl_object_id($post_id, 'page', false)); ?></h2>
@ivandoric
ivandoric / gist:11219021
Created Apr 23, 2014
wordpress: Automatically add category to post when certain other category is selected
View gist:11219021
<?php
function add_category_automatically1($post_ID) {
global $wpdb;
if(in_category(7)){
$cat = array(10);
wp_set_object_terms($post_ID, $cat, 'category', true);
}
}
add_action('publish_post', 'add_category_automatically1');
@ivandoric
ivandoric / gist:11220813
Created Apr 23, 2014
drupal: Print custom menu links
View gist:11220813
/*Print custom menu links*/
<?php print theme('links', menu_navigation_links('menu-MENU-NAME'), array('id' => 'menu', 'class' => 'links')); ?>
@ivandoric
ivandoric / gist:11212113
Created Apr 23, 2014
shell: Change owner group for all files
View gist:11212113
chown -R web37:client9 *
@ivandoric
ivandoric / gist:11219283
Created Apr 23, 2014
woocommerce: Add new currency to WooCommerce
View gist:11219283
<?php
// Just add it to functions.php
// Add currency / symbol
add_filter( 'woocommerce_currencies', 'add_rand_currency' );
add_filter( 'woocommerce_currency_symbol', 'add_rand_currency_symbol' );
function add_rand_currency( $currencies ) {
$currencies['HRK'] = __( 'Hrvatska kuna (Kn)', 'woothemes' );
@ivandoric
ivandoric / gist:11215702
Created Apr 23, 2014
sublime: Always use same indentation
View gist:11215702
Add this to Preferences - Settings user
"tab_size": 8,
"translate_tabs_to_spaces": true,
"auto_indent": true,
"detect_indentation": false
@ivandoric
ivandoric / gist:11219045
Created Apr 23, 2014
css: Target only Firefox with CSS
View gist:11219045
@-moz-document url-prefix() {
ul.nav li a {
padding:0 15px 2px 15px;
}
}
@ivandoric
ivandoric / gist:11215207
Created Apr 23, 2014
jQuery: Clear input and textarea fields on click
View gist:11215207
jQuery(function(){
jQuery('input, textarea').each(function(){
var txtval = jQuery(this).val();
jQuery(this).focus(function(){
jQuery(this).val('')
});
jQuery(this).blur(function(){
if(jQuery(this).val() == ""){
jQuery(this).val(txtval);
}