Skip to content

Instantly share code, notes, and snippets.

View raphaelchaib's full-sized avatar

Raphael Chaib raphaelchaib

View GitHub Profile
@raphaelchaib
raphaelchaib / functions.php
Created June 17, 2013 15:16
Wordpress: Exclude child categories of a category
<?php
// Exclude child categories of a category
function excluded_child_cats($id) {
// generates formatted string of sub cats
$ex_cats = get_categories('child_of=' . $id);
$result = '';
foreach ($ex_cats as $ec) {
$result .= ' -' . $ec->cat_ID;
}
@raphaelchaib
raphaelchaib / functions.php
Created June 17, 2013 17:05
Wordpress: Tests if any of a post's assigned categories are descendants of target categories
<?php
/**
* Tests if any of a post's assigned categories are descendants of target categories
*
* @param int|array $cats The target categories. Integer ID or array of integer IDs
* @param int|object $_post The post. Omit to test the current post in the Loop or main query
* @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
* @see get_term_by() You can get a category by name or slug, then pass ID to this function
* @uses get_term_children() Passes $cats
@raphaelchaib
raphaelchaib / functions.php
Created June 20, 2013 18:41
Wordpress: Deactivate wordpress autosave for a post type
<?php
// Deactivate wordpress autosave for a post type
add_action( 'admin_enqueue_scripts', 'my_admin_enqueue_scripts' );
function my_admin_enqueue_scripts() {
if ( 'your_post_type' == get_post_type() )
wp_dequeue_script( 'autosave' );
}
@raphaelchaib
raphaelchaib / functions.php
Last active December 19, 2015 02:58
WordPress: Remove links from WordPress Admin Bar
<?php
// The follow will remove the updates, comments, new content and performance links from the admin bar if the user isn't the admin user.
// On most WordPress blogs the admin user has the User ID of 1 so you can apply the following snippet.
function remove_admin_bar_links() {
global $wp_admin_bar, $current_user;
if ($current_user->ID != 1) {
$wp_admin_bar->remove_menu('updates'); // Remove the updates link
$wp_admin_bar->remove_menu('comments'); // Remove the comments link
$wp_admin_bar->remove_menu('new-content'); // Remove the content link
$wp_admin_bar->remove_menu('w3tc'); // If you use w3 total cache remove the performance link
@raphaelchaib
raphaelchaib / functions.php
Created June 28, 2013 19:58
WordPress: Exclude Pages from WordPress Search Results
<?php
// This code just searches for posts through setting the post_type.
// You can also make it do the opposite by setting the post_type to pages,
// so it only return pages in the search result.
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
@raphaelchaib
raphaelchaib / app.js
Last active December 19, 2015 05:19
CarouFredSel default config
$(window).ready(function() {
$("#slideshow ul").carouFredSel({
width: 650, // Alterar! Não esquecer de alterar no CSS também.
height: 300, // Alterar! Não esquecer de alterar no CSS também.
items: {
visible: 1
},
prev: {
button: '#slideshow .btn.left'
},
@raphaelchaib
raphaelchaib / app.js
Created July 23, 2013 17:14
Javascript: Disable right click
var msg="";
function clickIE()
{
if (document.all)
{
(msg);
return false;
}
}
@raphaelchaib
raphaelchaib / app.js
Created July 23, 2013 17:26
Disable text selection
function disableselect(e)
{
return false;
}
document.onselectstart=new Function ("return false");
if (window.sidebar){document.onmousedown=disableselect;
document.onclick=reEnable;}
@raphaelchaib
raphaelchaib / exclude_files_except
Last active December 20, 2015 04:39
Exclude files and directories via Linux's shell, except some of them.
find . ! -name one ! -name two -maxdepth 1 -type f -delete
@raphaelchaib
raphaelchaib / app.js
Created August 1, 2013 16:30
Javascript: Make #main's height go to footer and fill up all the page
// Make #main's height go to footer and fill up all the page
jQuery(document).ready(function() {
// Size that main have to be
var mainPredefinedHeight = jQuery(window).height()
- jQuery('#header').outerHeight(true)
- jQuery('#footer').outerHeight(true)
- parseInt(jQuery('#main').css('paddingBottom'))
;
if( jQuery('#main').height() < mainPredefinedHeight) {