Skip to content

Instantly share code, notes, and snippets.

View mbrughi's full-sized avatar

Marco Brughi mbrughi

View GitHub Profile
@mbrughi
mbrughi / functions.php
Created January 7, 2021 10:18
Wordpress: enable preview of .webp image files
// Enable preview / thumbnail for webp image files.
function display_webp($result, $path) {
if ($result === false) {
$webp_image_types = array( IMAGETYPE_WEBP );
$info = @getimagesize( $path );
if (empty($info)) {
$result = false;
} elseif (!in_array($info[2], $webp_image_types)) {
$result = false;
@mbrughi
mbrughi / functions.php
Last active January 7, 2021 10:07
Wordpress: upload files .webp
// Enable upload for webp image files.
function mb_webp_upload($addmimetype) {
$addmimetype['webp'] = 'image/webp';
return $addmimetype;
}
add_filter('mime_types', 'mb_webp_upload');
@mbrughi
mbrughi / functions.php
Created January 5, 2021 09:10
Wordpress: remove Gutenberg welcome popup.
/*
* Remove Gutenberg welcome popup
* @link https://marcobrughi.com
*
* @author Marco Brughi <[email protected]>
*
*/
function mb_enqueue_admin_script() {
if ( is_admin() ) {
wp_add_inline_script(
@mbrughi
mbrughi / functions.php
Created January 4, 2021 15:39
Wordpress: Add Google Tag Manager Code right after <body> open tag by wp_body_open hook.
/*
* Insert Google Tag Manager right after body open tag
* @link https://marcobrughi.com
*
* @author Marco Brughi <[email protected]>
*
* NB: Change Code with your's
*/
function mb_add_after_body_code() {
echo '<!-- Google Tag Manager (noscript) -->
@mbrughi
mbrughi / functions.php
Created January 4, 2021 15:28
Add Google Analytics code by wp_head in functions.php
/*
* Insert Google Analytics Code
* @link https://marcobrughi.com
*
* @author Marco Brughi <[email protected]>
*
* NB: Change Analytics Code with your's
*/
function mb_analytics_code() {
?>
@mbrughi
mbrughi / gist:8d76f9debfa1b12351001d95db2fa1bf
Created January 4, 2021 15:06
Add CSS by wp_head hook
function hook_css() {
?>
<style>
.wp_head_example {
background-color : #f1f1f1;
}
</style>
<?php
}
add_action('wp_head', 'hook_css');
@mbrughi
mbrughi / functions.php
Created January 4, 2021 14:43
Wordpress: add code into tags <head></head> by wp_head action hook.
/* Add code to WP Head */
function hook_javascript() {
?>
<script>
alert('Page is loading...');
</script>
<?php
}
add_action('wp_head', 'hook_javascript');
@mbrughi
mbrughi / gist:ea6babad6f533f3299123f27e4448f21
Created May 18, 2019 10:57
Wordpress: Custom image size. Add to functions.php
/**
* Custom Image Size for blog.
*/
add_image_size( 'home-blog', 1000, 536, true ); // 1000 pixels wide by 536 pixels tall, hard crop mode
@mbrughi
mbrughi / breadcrumb.php
Last active May 18, 2019 10:55
Wordpress: breadcrumb function snippet.
<?php
/*=============================================
BREADCRUMBS
=============================================*/
// to include in functions.php
function the_breadcrumb()
{
$showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
$delimiter = '&raquo;'; // delimiter between crumbs
$home = 'Home'; // text for the 'Home' link
function cf7_add_post_id(){
global $post;
return $post->ID;
}
add_shortcode('CF7_ADD_POST_ID', 'cf7_add_post_id');