Skip to content

Instantly share code, notes, and snippets.

function mg_clean_custom_menu( $theme_location ) {
if ( ( $theme_location )
&& ( $locations = get_nav_menu_locations() )
&& isset($locations[$theme_location]) ) {
$menu = get_term( $locations[$theme_location], 'nav_menu' );
$menu_items = wp_get_nav_menu_items($menu->term_id);
// $menu_list = '<nav>' ."\n";
$menu_list .= '<ul class="nav nav-pills">' ."\n";
@tacensi
tacensi / term hierarchy
Created January 7, 2016 18:38
Create an hierarchaly ordere array of terms
// Hierarchaly ordered array of terms
function sort_terms_hierarchicaly( Array &$cats, Array &$into, $parentId = 0 ) {
foreach ( $cats as $i => $cat ) {
if ( $cat->parent == $parentId ) {
$into[$cat->term_id] = $cat;
unset( $cats[$i] );
}
}
foreach ( $into as $topCat ) {
@tacensi
tacensi / gradient.scss
Created December 1, 2015 01:39
Gradient mixin
// ================
// G R A D I E N T
// M I X I N
// ================
// from http://codepen.io/Hornebom/pen/epqmGx/
// Built upon the logic found in a ps file
// element has a solid background
// background is covered by a gradient of one color
// one can define the opacity of the two color stops + the gradient angle
@tacensi
tacensi / cf7-blank.php
Created May 25, 2015 21:05
Change CF7 select blank line
// Alterando o texto da blank line do Contact form 7
function my_wpcf7_form_elements($html) {
$text = 'Selecione o departamento';
$html = str_replace('<option value="">---</option>', '<option value="">' . $text . '</option>', $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
@tacensi
tacensi / Responsive embeds
Created May 5, 2015 14:38
Responsive embeds
.video{
width: 100%;
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;
margin-bottom: 15px;
}
@tacensi
tacensi / Vimeo oembed parameters
Created March 11, 2015 19:50
Add aditional parameters do Vimeo oembed
add_filter('oembed_result', 'custom_oembed_result', 10, 3);
function custom_oembed_result($html, $url, $args) {
if ($args) {
$newargs = $args;
$parameters = http_build_query($newargs);
$html = preg_replace('/(player.vimeo.com\/video\/[0-9]*)/i', '$1?' . $parameters, $html);
}
return $html;
}
@tacensi
tacensi / Remove trash from wp_head
Created February 19, 2015 00:25
Remove trash from wp_head
// remove unncessary header info
function frq_remove_header_info() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
}
add_action('init', 'frq_remove_header_info');
@tacensi
tacensi / get_excerppt_by_id
Created February 12, 2015 17:01
Get a post excerpt by id
// get excerpt by id
function mg_get_the_excerpt($post_id) {
global $post;
$save_post = $post;
$post = get_post($post_id);
$output = get_the_excerpt();
$post = $save_post;
return $output;
}
@tacensi
tacensi / WP Post excerpt length
Created February 12, 2015 17:00
Define the WP Post excerpt length
// Excerpt length
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
@tacensi
tacensi / scrollTop
Created February 12, 2015 13:54
JQuery Scroll Top Animated
try{
$('.backtop').click( function(e){
e.preventDefault();
$('html,body').animate({
scrollTop: '0px'
}, 800 );
})
} catch(e){
console.log(e);
}