Skip to content

Instantly share code, notes, and snippets.

View raphaelchaib's full-sized avatar

Raphael Chaib raphaelchaib

View GitHub Profile
@raphaelchaib
raphaelchaib / style.css
Created March 21, 2013 15:01
CSS: Fullscreen background
img#fullscreen-bg {
width: 100%;
min-width: 1024px;
height: auto;
position: fixed;
top: 0;
left: 0;
z-index: -999;
}
@raphaelchaib
raphaelchaib / app.js
Last active December 15, 2015 06:09
jQuery: Scroll sidebar with window. (It's necessary that the sidebar it's absolute positioned and have a wrapper with absolute position too)
jQuery(document).ready(function() {
var page = jQuery('.single.post');
var sidebar = jQuery('.single.post .scrolling-sidebar');
var content = jQuery('.single.post .content');
// Scroll with screen
var top = sidebar.offset().top;
var limit = top + page.height() - sidebar.height();
// Define sidebar-wrapper height
@raphaelchaib
raphaelchaib / functions_custom.php
Last active December 15, 2015 06:09
Wordpress: Custom excerpt size on any part of code
<?php
function custom_excerpt($new_length = 20, $new_more = '...') {
add_filter('excerpt_length', function () use ($new_length) {
return $new_length;
}, 999);
add_filter('excerpt_more', function () use ($new_more) {
return $new_more;
});
@raphaelchaib
raphaelchaib / functions.php
Last active December 15, 2015 06:09
Wordpress: Remove admin's menu options for end-user
<?php
// Remove admin's menu options
add_action('admin_menu', 'remove_menu_options');
function remove_menu_options () {
global $menu;
$remove = array(__('Links'), __('Posts'), __('Comments'), /*__('Dashboard'),*/ __('Tools'), /*__('Appearance'),*/ __('Plugins'), __('Users'), __('Settings'));
end($menu);
@raphaelchaib
raphaelchaib / functions.php
Last active December 15, 2015 06:09
Wordpress: Get post slug
<?php
// Return post's slug
function the_slug($echo=true) {
$slug = basename(get_permalink());
do_action('before_slug', $slug);
$slug = apply_filters('slug_filter', $slug);
if( $echo ) echo $slug;
do_action('after_slug', $slug);
return $slug;
@raphaelchaib
raphaelchaib / config.php
Last active December 15, 2015 06:09
PHP: Localization configuration
<?php
/* -------------------- LOCALIZATION -------------------- */
// PHP INI charset
ini_set("default_charset", "UTF-8");
// Default timezone
date_default_timezone_set('America/Sao_Paulo');
@raphaelchaib
raphaelchaib / gist:5213892
Created March 21, 2013 15:24
Code to disable web site's cache across all browsers. Works on: HTML, PHP, Ruby on Rails, Java Servlet and ASP.NET.
The correct minimum set of headers that works across all mentioned browsers:
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Using PHP:
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
@raphaelchaib
raphaelchaib / app.js
Created March 21, 2013 18:40
Javascript: Scroll window to top. For this snippet work the container of icon (or text) must be "display: none" for fade-in and fade-out.
// Scroll to top
jQuery(window).scroll(function() {
if( jQuery(this).scrollTop() != 0 ) {
jQuery('.scroll-to-top').fadeIn();
} else {
jQuery('.scroll-to-top').fadeOut();
}
});
@raphaelchaib
raphaelchaib / taxonomy.php
Created March 25, 2013 14:24
Wordpress: Taxonomy default schema
<?php
//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_book_taxonomies', 0 );
//create two taxonomies, genres and writers for the post type "book"
function create_book_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Genres', 'taxonomy general name' ),
@raphaelchaib
raphaelchaib / functions.php
Created March 28, 2013 19:59
WordPress: Show post's attachment images
<?php
// Show post's attachment images
function show_attachment_images() {
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => 42,
'exclude' => get_post_thumbnail_id()
) );