Skip to content

Instantly share code, notes, and snippets.

View chrdesigner's full-sized avatar

César Ribeiro chrdesigner

View GitHub Profile
@chrdesigner
chrdesigner / functions.php
Last active December 12, 2015 18:20
Transform HEX to RGB with PHP
<?php
function hex2RGB($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
@chrdesigner
chrdesigner / list-tag-wordpress
Last active December 21, 2015 03:48
Listagem de tags com o título e o link para Wordpress
<ul>
<?php $tags = get_the_tags(); foreach ( (array) $tags as $tag ) { echo '<li><a href="' . get_tag_link($tag->term_id) . '" title="' . $tag->name . '">' . $tag->name . '</a></li>';}?>
</ul>
@chrdesigner
chrdesigner / list-link-manager
Created August 15, 2013 20:19
Em "ID-CATEGORIA" adicionar o ID correto da sua galeria de links.
@chrdesigner
chrdesigner / show-sigle-cat-title
Created August 16, 2013 13:31
Essa função mostra o nome da categoria referente ao post que esta cadastrado.
<?php global $post; $category = get_the_category($post->ID); echo $category[0]->name; ?>
<?php if(get_post_custom_values('SEU-CUSTOM-FILD')) { foreach(get_post_custom_values('SEU-CUSTOM-FILD') as $suavarivel) { echo wpautop($suavarivel); } } ?>
@chrdesigner
chrdesigner / show_future_post.php
Last active December 29, 2015 10:29
Display posts with 'future' status
<?php
add_filter('the_posts', 'show_future_posts');
function show_future_posts($posts)
{
global $wp_query, $wpdb;
if(is_single() && $wp_query->post_count == 0)
{
$posts = $wpdb->get_results($wp_query->request);
<?php
global $post;
$trim_length = 450; //desired length of text to display
$summary_excerpt = 'wpcf-breve-descricao';
$value = get_post_meta($post->ID, $summary_excerpt, true);
if ($value != '') {
if(strlen($value) <= $trim_length){
echo apply_filters('breve-descricao', $value);
} else {
echo apply_filters('breve-descricao', rtrim(substr($value,0,$trim_length)).'...');
@chrdesigner
chrdesigner / functions.php
Last active January 4, 2016 23:57
Set a custom post type to not show up on the frontend - WordPress
<?php
function chr_redirect_post_type() {
global $wp_query;
if ( is_post_type_archive('sliders') || is_singular('sliders') ) :
$url = get_bloginfo('url');
wp_redirect( esc_url_raw( $url ), 301 );
exit();
endif;
}
add_action ( 'template_redirect', 'chr_redirect_post_type', 1);