Skip to content

Instantly share code, notes, and snippets.

View alanpilloud's full-sized avatar

Alan alanpilloud

View GitHub Profile
@alanpilloud
alanpilloud / minify_html
Last active August 29, 2015 14:22
Minify HTML output
<?php
/*
* Will minify HTML
*/
ob_start(function($b){return preg_replace(['/\>[^\S ]+/s','/[^\S ]+\</s','/(\s)+/s'],['>','<','\\1'],$b);});
?>
@alanpilloud
alanpilloud / wp-config.php
Last active November 7, 2016 10:58
usefull config options #wp
<?php
define('DISALLOW_FILE_EDIT', true);
define('WP_DEBUG', true);
define('WP_AUTO_UPDATE_CORE', false);
define('WP_POST_REVISIONS', false );
if ( WP_DEBUG ) {
define( 'WP_DEBUG_LOG', true ); //Log errors in a file
define( 'WP_DEBUG_DISPLAY', false ); //blocks message display on the website
define('SAVEQUERIES', true); //Save MySql queries in the global var $wpdb->queries
<?php
class MyConfig extends Config
{
public function __construct()
{
$faker = Faker\Factory::create('en_GB');
$this->post_type = 'post';
$this->post_title = $faker->name();
@alanpilloud
alanpilloud / svg-sprite.md
Last active January 4, 2016 13:37
Faire un sprite avec SVG-Sprite
svg-sprite --si --stack icons/*.svg
@alanpilloud
alanpilloud / cron-example.php
Last active June 16, 2016 08:02
This is how I add a cron action in a WordPress Plugin #wp
<?php
/*
Plugin Name: My Cronjobs
*/
defined('ABSPATH') or die;
/**
* Add Cron when the theme is activated
*/
<?php
/*
Plugin Name: Bwap Shortcodes
Description: Add shortcodes you write
Version: 0.1
Author: Bwap
*/
defined( 'ABSPATH' ) or die;
/**
<!--
Make sure that the viewBox attributes are using the same values.
xlink:href should refer to the id of the <svg> and have a # sign before it.
-->
<div style="display:none">
<svg id="mySVG" width="50" height="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg">...</svg>
</div>
<svg viewBox="0 0 50 50"><use xlink:href="#mySVG"></use></svg>
@alanpilloud
alanpilloud / wp-youtube-embed.php
Last active June 16, 2016 08:01
Embed youtube vidéos #wp
<?php
/**
* Responsive Youtube embeds.
*
* Adds bootstrap responsive embed markup and classes and avoid showing related
* videos at the end of the videos.
*/
add_filter( 'embed_oembed_html', function( $html, $url, $attr, $post_ID ) {
if ( false !== stripos( $html, '<iframe ' ) && false !== stripos( $html, '.youtube.com/embed' ) ) {
//don't show related videos
@alanpilloud
alanpilloud / clean-smartcrawl-metabox.php
Created July 22, 2016 12:20
Cleaning Smartcrawl metabox
<?php
/**
* Cleaning Smartcrawl metabox
*/
add_action('admin_head', function() {
echo '
<style>
#wds-wds-meta-box .widefat tr{display:none}
#wds-wds-meta-box .widefat tr:nth-child(1),
#wds-wds-meta-box .widefat tr:nth-child(2),
@alanpilloud
alanpilloud / theme-widget-documents.php
Created July 25, 2016 11:38
Add admin dashboard widgets for each .md file found in theme root.
<?php
/**
* Add admin dashboard widgets for each .md file found in theme root.
*
* reads the *.md markdown files at the root of the theme and display a widget for each .md in the admin dashboard
* <!> Requires the class Parsedown https://github.com/erusev/parsedown
* <!> includes classes/Parsedown.php
*/
add_action('wp_dashboard_setup', function(){
$themeDir = get_template_directory();