Skip to content

Instantly share code, notes, and snippets.

View gmaggio's full-sized avatar

Giraldi Maggio gmaggio

View GitHub Profile
@gmaggio
gmaggio / wp-post-twitter-fb-share.php
Created July 26, 2014 03:33
[Wordpress] Add Twitter & Facebook share buttons to posts
<?php
add_action('the_content', 'my_share_this');
/**
* Add Twitter & Facebook share buttons to posts
*
* Sources:
* - http://wordpress.stackexchange.com/questions/125838/how-to-create-really-simple-wordpress-custom-buttons-for-print-facebook-share-a
* - http://www.catswhocode.com/blog/wordpress-snippets-to-interact-with-social-networks
*
*/
@gmaggio
gmaggio / jquery-row-height-equal.js
Created July 19, 2014 19:38
[jQuery] Equal Height Rows - Responsive
/**
* Equal Height Rows - Responsive
*
* Source:
* http://codepen.io/micahgodbolt/pen/FgqLc?editors=101
* http://css-tricks.com/equal-height-blocks-in-rows/
*
*/
equalheight = function(container){
@gmaggio
gmaggio / wp-navmenu-insert-item.php
Created July 9, 2014 21:39
[Wordpress] Insert custom menu items via hard coding
<?php
// Sample: Add HOME link to Nav Menu
function new_nav_menu_items($items, $args) {
if( $args->theme_location == 'primary' ){
$homelink = '<li class="home"><a href="' . home_url( '/' ) . '">' . __('Home') . '</a></li>';
$items = $homelink . $items;
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items', 10, 2 );
@gmaggio
gmaggio / wp-redirect-login-nonadmin.php
Created July 4, 2014 23:15
[Wordpress] Redirect Non-Admin Users to Homepage After Login ( http://tommcfarlin.com/redirect-non-admin/ )
<?php
/**
* Redirect non-admins to the homepage after logging into the site.
*
*/
function my_login_redirect ( $redirect_to, $request, $user ) {
return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url();
} // end my_login_redirect
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
@gmaggio
gmaggio / wp-img-size-preset.php
Created July 2, 2014 17:41
[Wordpress] Pre-set default image sizes (programatically), thus sizes become fixed & unchangable.
<?php
update_option( 'thumbnail_size_h', 150 );
update_option( 'thumbnail_size_w', 150 );
update_option( 'medium_size_h', 500 );
update_option( 'medium_size_w', 500 );
update_option( 'large_size_h', 1000 );
update_option( 'large_size_w', 1000 );
@gmaggio
gmaggio / jquery-toggle-height.js
Created July 1, 2014 08:58
[jQuery] Toggle height of element in jQuery
var intH = 0,
finH = 40;
$(document).ready(function(){
$("#topbar").click(function () {
$(this).animate({
height: ($(this).height() == finH) ? intH : finH
}, 200);
});
@gmaggio
gmaggio / jquery-list-shorten-hide-show.js
Created June 23, 2014 06:56
[jQuery] Hide & show list items after nth item
$(document).ready(function(){
// Source: http://stackoverflow.com/a/7973317/851045
$('ul.sub-category').each(function(){
var max = 3
if ($(this).find("li").length > max+1) {
$(this)
.find('li:gt('+max+')')
.hide()
.end()
@gmaggio
gmaggio / wp-front-content-excerpt.php
Created June 15, 2014 14:41
[Wordpress] Set custom excerpt length
/*-----------------------------------------------------------------------------------*/
/* Set custom excerpt length */
/*-----------------------------------------------------------------------------------*/
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function custom_excerpt_length( $length ) {
global $excerpt_length;
if ( $excerpt_length ) {
@gmaggio
gmaggio / wp-admin-menu-home.php
Created June 15, 2014 14:37
[Wordpress] Add option to link to Homepage in custom menu.
/*-----------------------------------------------------------------------------------*/
/* Add option to link to Homepage in custom menu */
/*-----------------------------------------------------------------------------------*/
if ( ! function_exists( 'home_page_menu_args' ) ) {
function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );