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
Last active December 15, 2015 15:59
Customize "Featured Image" in Wordpress post types
<?php
// Use "Featured Image" box as a custom box
add_action('do_meta_boxes', 'customposttype_image_box');
function customposttype_image_box()
{
// remove_meta_box( $id, $page, $context );
remove_meta_box('postimagediv', 'post_type', 'side');
// add_meta_box( $id, $title, $callback, $post_type, $context,
@raphaelchaib
raphaelchaib / app.js
Created April 1, 2013 18:38
Sticky float box
(function (c) {
c.fn.stickyfloat = function (l) {
var b = this,
f = c(document),
h = parseInt(b.parent().css("padding-top")),
g = b.parent().offset().top,
a, d, i, j, k, e;
a = c.fn.stickyfloat.opts;
c.extend(a, {
startOffset: g,
@raphaelchaib
raphaelchaib / functions.php
Last active December 15, 2015 20:49
Custom excerpt class for Wordpress Add to functions.php
<?php
//Custom excerpt class for Wordpress
class Excerpt {
// Default length (by WordPress)
public static $length = 55;
// Default more (by WordPress)
public static $more = '[...]';
@raphaelchaib
raphaelchaib / general.php
Created April 9, 2013 16:37
Check if page/post is parent or if it has ancestors on Wordpress.
<?php
if ( is_page('americas') || $post->post_parent == '2348' || ($post->ancestors && in_array( '2348', $post->ancestors) ) ) {
}
@raphaelchaib
raphaelchaib / custom_functions.php
Created April 10, 2013 14:57
Excerpt or content word limit in WordPress
<?php
// Custom excerpt word limit
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
@raphaelchaib
raphaelchaib / functions.php
Created April 11, 2013 19:13
Remove links from images on Wordpress posts
<?php
// Remove links from images on Wordpress posts
add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content )
{
$content =
preg_replace(array(
'{<a(.*?)(wp-att|wp-content/uploads)[^>]*><img}',
'{ wp-image-[0-9]*" /></a>}'
@raphaelchaib
raphaelchaib / functions.php
Last active December 16, 2015 23:39
Remove default css classes and IDs from wp_nav_menu
<?php
function my_nav_menu_css_class($classes) {
$custom_classes = array();
foreach($classes as $class) {
if($class=='menu-item') return $custom_classes;
$custom_classes[] = $class;
}
}
function my_nav_menu_css_id($id) {
@raphaelchaib
raphaelchaib / functions.php
Created June 14, 2013 18:40
Wordpress: Custom PHPMailer configuration via functions.php
<?php
// Custom PHPMailer configuration
add_action( 'phpmailer_init', 'cg_custom_phpmailer_config' );
function cg_custom_phpmailer_config( PHPMailer $phpmailer ) {
$phpmailer->From = 'email@email.com.br';
$phpmailer->FromName = '';
$phpmailer->Sender= 'email@email.com.br';
$phpmailer->Host = 'smtp.server.com.br';
$phpmailer->Port = 587; // could be different
$phpmailer->Username = 'email@email.com.br'; // if required
@raphaelchaib
raphaelchaib / functions.php
Last active December 18, 2015 12:39
Wordpress: Get Category ID by name, slug or id
<?php
// Get Category ID by name, slug or id
function get_category_id($cat_slug, $field = 'slug', $taxonomy = 'category'){
$term = get_term_by($field, $cat_slug, $taxonomy);
return $term->term_id;
}
@raphaelchaib
raphaelchaib / general.php
Created June 17, 2013 13:49
Wordpress: Get permalink by slug/title
<?php
// Get permalink by slug
get_permalink( get_page_by_path( 'map' ) );
// Get permalink by title
get_permalink( get_page_by_title( 'Map' ) );