Skip to content

Instantly share code, notes, and snippets.

View gmaggio's full-sized avatar

Giraldi Maggio gmaggio

View GitHub Profile
@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' );
@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 / 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 / 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 / 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 / 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 / yahoo-online-status-detection.php
Created July 8, 2014 11:42
[Yahoo] Yahoo Messenger Online/Offline Status Detection #soical-media
<?php
$yahooID = "YOUR_ID";
$status = file_get_contents("http://opi.yahoo.com/online?u=".$yahooID."&m=a&t=1");
if ($status === '00') {
echo "OFFLINE!";
} else if ($status === '01') {
echo "ONLINE!";
@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 / 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-add-class-next_prev_post_links.php
Created July 20, 2014 17:11
[Worpress] Add class to next/previous post links (Add class to links generated by next_posts_link & previous_posts_link)
<?php
/**
* Add class to next/previous post links
*
* Add class to links generated by next_posts_link
* and previous_posts_link
*/
if ( ! function_exists( 'posts_link_attributes_prev' ) || ! function_exists( 'posts_link_attributes_next' ) ) {
function posts_link_attributes_prev() {