Skip to content

Instantly share code, notes, and snippets.

View celsofabri's full-sized avatar
👾
The truth is dubious

Celso Fabri Junior celsofabri

👾
The truth is dubious
View GitHub Profile
@celsofabri
celsofabri / scroll_top.js
Created December 15, 2014 12:17
Scroll Top / Voltar ao Topo
// Voltar ao Topo
$('.vr').on('click', function () {
$('body, html').animate({
scrollTop: 0
});
return false;
@celsofabri
celsofabri / page-slug-body-class.php
Created December 15, 2014 12:21
Page Slug Body Class / Slug da página como classe
<?php
// Page Slug Body Class
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
@celsofabri
celsofabri / add-remove-class.js
Created December 16, 2014 19:47
Add and Remove Class with Javascript / Adicionar e Remover Classe com Javascript
var variavel = document.querySelector('.title-main');
variavel.addEventListener('click', function() {
if(variavel.classList.contains('classe')) {
this.classList.remove('classe');
}
else {
this.classList.add('classe');
@celsofabri
celsofabri / words_limit.php
Created January 26, 2015 16:03
Excerpt or Content Word Limit in WordPress / Resumo ou Conteúdo com limite de palavras WordPress
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
@celsofabri
celsofabri / return-string.php
Created February 24, 2015 19:20
Returns hum summary for any rope word / Retorna um resumo de qualquer string por palavra
/**
* Retorna um resumo de qualquer string por palavra
* @param string $string A string que será cortada
* @param int $max O número máximo de palavras
* @return string A string cortada
* By Cezinha <3
*/
function resumo($string, $max, $final = '...') {
$string = explode(' ', trim($string));
@celsofabri
celsofabri / mobile-detect.js
Created September 14, 2015 18:08
Identifica dispositivo mobile
$(function(){
function device_detect() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)){
alert('Seu dispositivo mobile foi detectado');
@celsofabri
celsofabri / loop-author.php
Created October 8, 2015 20:20
Author Loop WordPress / Looping de Autores WordPress
<?php
$args = get_users(array(
'blog_id' => 1,
'orderby' => 'nicename',
'role' => 'editor'
));
foreach ( $args as $user ) {
echo '<span>' . esc_html( $user->description ) . '</span>';
@celsofabri
celsofabri / loop-page.php
Created October 21, 2015 13:46
Loop de Página (Section) / Loop Page
<!-- Loop com ID -->
<?php $my_query = new WP_Query('page_id=87');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<div class="entry">
<?php the_content(); ?>
</div>
@celsofabri
celsofabri / add_body_class_wpmu.php
Last active November 6, 2017 01:08
Add Class Body Multisite / Adicionando Classe Body para Multisite
<?php
// Apply filter
add_filter('body_class', 'multisite_body_classes');
function multisite_body_classes($classes) {
$id = get_current_blog_id();
$slug = strtolower(str_replace(' ', '-', trim(get_bloginfo('name'))));
$classes[] = sanitize_title('site-'.$slug);
return $classes;
}
@celsofabri
celsofabri / functions.php
Created July 26, 2016 02:54 — forked from cezarsmpio/functions.php
Wordpress - Get the post terms
<?php
/**
* Get the terms of post
* @param object $p The post
* @param string $class CSS Class
* @param string $separator
* @return string The terms
*/
function get_post_terms($p, $class = 'post-preview__cat', $separator = '') {