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
#element{
-webkit-transition: all 350ms ease;
-moz-transition: all 350ms ease;
-o-transition: all 350ms ease;
transition: all 350ms ease;
}
@brunomonteiro3
brunomonteiro3 / seo-url.php
Last active April 6, 2016 16:10
SEO friendly URL. "Löng Strîng" will be converted to > "long-string".
<?php
function seoUrl($string, $separator = '-') {
$accents_regex = '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i';
$special_cases = array( '&' => 'and', "'" => '');
$string = mb_strtolower( trim( $string ), 'UTF-8' );
$string = str_replace( array_keys($special_cases), array_values( $special_cases), $string );
$string = preg_replace( $accents_regex, '$1', htmlentities( $string, ENT_QUOTES, 'UTF-8' ) );
$string = preg_replace("/[^a-z0-9]/u", "$separator", $string);
$string = preg_replace("/[$separator]+/u", "$separator", $string);
return $string;
@brunomonteiro3
brunomonteiro3 / base64-black-color-pixel.txt
Created November 18, 2015 13:09
Base64 1x1 black color pixel with opacity.
75% opacity:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlPCNYx7+gAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=
@brunomonteiro3
brunomonteiro3 / get-attachments.php
Created October 20, 2015 13:02
List all attachments of a post or page in Wordpress.
<?php
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id(),
'orderby' => 'menu_order',
'order' => 'ASC'
) );
@brunomonteiro3
brunomonteiro3 / featured-thumbnail-column.php
Created October 17, 2015 14:41
Show the featured image from each post on Wordpress dashboard.
@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();
@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 / 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 / get-featured-image.php
Created August 3, 2015 14:04
Get featured image on Wordpress.
@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' );