Skip to content

Instantly share code, notes, and snippets.

View andregomes's full-sized avatar

André Gomes andregomes

View GitHub Profile
@andregomes
andregomes / slug.php
Created March 25, 2013 23:43
PHP: Slug for friendly URL's
<?php
/*
* http://necenzurat.net/2010/05/26/clean-up-and-url-like-wordpress-does.dev
* Create a slug for friendly URL's a-la wordpress
*/
function clean_url($str) {
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
@andregomes
andregomes / admin-functions.php
Created March 25, 2013 23:38
Wordpress: Custom WordPress Admin Color Scheme
<?php
// Custom WordPress Admin Color Scheme
function admin_css() {
wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/css/admin.css' );
}
add_action('admin_print_styles', 'admin_css' );
?>
@andregomes
andregomes / functions.php
Created March 25, 2013 23:35
Wordpress: Add SVG upload support to a theme
<?php
// add to functions.php in your WordPress theme
add_filter('upload_mimes', 'm6z_upload_mimes');
function m6z_upload_mimes($mimes = array())
{
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
?>
@andregomes
andregomes / functions.php
Created March 25, 2013 23:32
Wordpress: Add Lightbox to Wordpress Gallery
<?php // Add Lightbox to Wordpress Gallery
add_filter( 'wp_get_attachment_link', 'm6z_addlightbox2gal');
function m6z_addlightbox2gal ($content) {
$content = preg_replace("/<a/","<a rel=\"prettyPhoto[slides]\" class=\"preloader\"",$content,1);
return $content;
} ?>
@andregomes
andregomes / functions.php
Created March 25, 2013 23:30
WordPress: Add Class to first Paragraph in WordPress the_content
<?php
/* =BEGIN: Add Class to first Paragraph in WordPress the_content();
Source: http://webdevbits.com/wordpress/add-class-to-first-paragraph-in-wordpress-the_content/
---------------------------------------------------------------------------------------------------- */
function first_paragraph($content){
// Testing to see if the content is a Page or Custom Post Type of school, if so, display the text normally (without the class = intro).
if ( is_page() || ('school' == get_post_type() ) ) {
return preg_replace('/<p([^>]+)?>/', '<p$1>', $content, 1);
} else {
return preg_replace('/<p([^>]+)?>/', '<p$1 class="intro">', $content, 1);
@andregomes
andregomes / index.php
Created March 25, 2013 23:26
Wordpress em páginas externas
<?php
/**
* Carrega a API do WordPress
*/
define('WP_USE_THEMES', false); // Não utiliza nenhum tema
require('./wordpress/wp-load.php');
 
query_posts('showposts=1');
 
while (have_posts()): the_post();
@andregomes
andregomes / functions.php
Created March 25, 2013 23:02
Enable Kitchen Sink in Wordpress TinyMCE by default
<?php
function unhide_kitchensink( $args ) {
$args['wordpress_adv_hidden'] = false;
return $args;
}
add_filter( 'tiny_mce_before_init', 'unhide_kitchensink' );
?>
@andregomes
andregomes / ajax.php
Created March 25, 2013 23:00
PHP: Parse JSON
<?php
$json ='{"id":1,"name":"foo","interest":["wordpress","php"]} ';
$obj=json_decode($json);
echo $obj->interest[1]; //prints php
?>
@andregomes
andregomes / functions.php
Created March 25, 2013 22:58
Wordpress: Full TinyMCE Editor
<?php
function all_tinymce( $args ) {
$args['wordpress_adv_hidden'] = false;
return $args;
}
add_filter( 'tiny_mce_before_init', 'all_tinymce' );
@andregomes
andregomes / WP Dashboard
Created March 25, 2013 22:57
Remove Dashboard unwanted metaboxes
// Remove unwanted dashboard metaboxes
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
 
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
 
//QuickPress
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
//Wordpress Development Blog Feed
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);