Skip to content

Instantly share code, notes, and snippets.

View brunomonteiro3's full-sized avatar

Bruno Monteiro brunomonteiro3

  • Empiricus Research
  • São Paulo, Brazil
View GitHub Profile
@brunomonteiro3
brunomonteiro3 / Item slug on menu option class
Last active August 29, 2015 14:24
This code will add an class to each item on your theme menu - this way you can customize each item based on their slug rather than their ID (which can change when the database changes).
function add_slug_class_to_menu_item($output){
$ps = get_option('permalink_structure');
if(!empty($ps)){
$idstr = preg_match_all('/<li id="menu-item-(\d+)/', $output, $matches);
foreach($matches[1] as $mid){
$id = get_post_meta($mid, '_menu_item_object_id', true);
$slug = basename(get_permalink($id));
$output = preg_replace('/menu-item-'.$mid.'">/', 'item-'.$slug.'">', $output, 1);
}
}
@brunomonteiro3
brunomonteiro3 / Taxonomy items list (inside a post)
Created July 15, 2015 21:09
This code will list all the terms from a taxonomy that are associated with a post. Must be inside a loop.
<?
$yourTaxonomySlugHere = get_the_terms($post->ID, 'yourTaxonomySlugHere');
if ($terms) :
foreach ($terms as $term) :
echo $term->name;
endforeach;
endif;
?>
@brunomonteiro3
brunomonteiro3 / sass --watch with automatic minify
Last active August 29, 2015 14:25
Using this command, the output file will be minified.
sass --watch a.scss:a.css --style compressed
@brunomonteiro3
brunomonteiro3 / remove-emoji.php
Created July 21, 2015 13:45
Remove Emoji and Smiley from wp_head();
<?php
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
@brunomonteiro3
brunomonteiro3 / taxonomy.php
Last active August 29, 2015 14:26
Taxonomy template for Wordpress
<?php
$taxonomy = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy'));
?>
@brunomonteiro3
brunomonteiro3 / custom-login.php
Created July 29, 2015 21:22
Custom logo and URL on Wordpress admin.
<?php
function my_login_logo() { ?>
<style type="text/css">
.login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/path/to/logo.png);
}
</style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo' );
@brunomonteiro3
brunomonteiro3 / get-featured-image.php
Created August 3, 2015 14:04
Get featured image on Wordpress.
@brunomonteiro3
brunomonteiro3 / gist:60ffc3decb79978fef7f
Last active August 5, 2022 14:06
Change Wordpress main URLs
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.oldurl', 'http://www.newurl') WHERE post_type='posts' AND post_status='publish'
@brunomonteiro3
brunomonteiro3 / viewportsize.js
Last active April 8, 2022 19:57 — forked from thiagoeliasr/viewportsize.js
Display ViewPort and Screen Resolution at the top of screen. (This script was created intended to be a bookmarklet)
$(document).find('body').append('<div id="div-width-top" style="position: fixed; right: 5px; top: 5px; background: #000; color: #fff; padding: 10px; z-index: 99999; opacity: 0.7">Window Size:</div>');
$('#div-width-top').html('ViewPort: ' + window.innerWidth + 'px | Window: ' + screen.width + 'px');
$(window).resize(function() {
$('#div-width-top').html('ViewPort: ' + window.innerWidth + 'px | Window: ' + screen.width + 'px');
});
@brunomonteiro3
brunomonteiro3 / cross-domain.php
Created September 11, 2015 13:32
Allow Cross-domain requests on Wordpress
add_action( 'init', 'handle_preflight' );
function handle_preflight() {
header("Access-Control-Allow-Origin: " . get_http_origin());
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Credentials: true");
if ( 'OPTIONS' == $_SERVER['REQUEST_METHOD'] ) {
status_header(200);
exit();