Skip to content

Instantly share code, notes, and snippets.

@walterebert
walterebert / functions.php
Created January 24, 2016 13:59
WordPress snippet: Remove WordPress News from Dashboard
<?php
add_action( 'admin_menu', function() {
remove_meta_box( 'dashboard_primary', 'dashboard', 'core' );
} );
@walterebert
walterebert / script.js
Created January 20, 2016 12:12
JavaScript: Detect mobile + add class to html root
if (navigator.userAgent.match(/Mobi/)) document.documentElement.className += " is-mobile";
@walterebert
walterebert / functions.php
Last active March 12, 2018 10:44
WordPress snippet: Load JavaScript asynchronously
function my_async_scripts( $tag, $handle, $src ) {
switch ( $handle ) {
case 'picturefill':
case 'wp-embed':
$tag = str_replace( ' src=', ' async defer src=', $tag );
break;
}
return $tag;
}
@walterebert
walterebert / composer.json
Last active May 29, 2023 06:40
WordPress: Install Advanced Custom Fields (Pro) with Composer
{
"type" : "project",
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"secure-http": false
},
"repositories" : [
{
"type" :"composer",
@walterebert
walterebert / functions.php
Created December 9, 2015 20:26
WordPress snippet: Disable emojis
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', function( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
@walterebert
walterebert / functions.php
Created November 10, 2015 11:10
WordPress snippet: Hide admin menus
<?php
function my_admin_menus() {
if ( ! current_user_can( 'remove_users' ) ) { // See: https://codex.wordpress.org/Roles_and_Capabilities
// remove_menu_page( 'index.php' ); // Dashboard
// remove_menu_page( 'edit.php' ); // Posts
// remove_menu_page( 'upload.php' ); // Media
// remove_menu_page( 'edit.php?post_type=page' ); // Pages
// remove_menu_page( 'edit-comments.php' ); // Comments
// remove_menu_page( 'themes.php' ); // Appearance
// remove_menu_page( 'plugins.php' ); // Plugins
@walterebert
walterebert / functions.php
Created November 10, 2015 10:28
WordPress snippet: Add mobile CSS class
<?php
function my_body_class( $classes ) {
if ( wp_is_mobile() ) {
$classes[] = 'is-mobile';
}
return $classes;
}
add_filter( 'body_class', 'my_body_class' );
@walterebert
walterebert / functions.php
Created November 10, 2015 10:24
WordPress snippet: Increase timeout for HTTP requests
<?php
function my_http_api_curl( $handle ) {
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 180 );
curl_setopt( $handle, CURLOPT_TIMEOUT, 180 );
}
add_action( 'http_api_curl', 'my_http_api_curl', 100, 1 );
@walterebert
walterebert / functions.php
Last active November 10, 2015 10:18
WordPress snippet: Disable plugin/theme updates
<?php
add_filter( 'auto_update_plugin', '__return_false' );
add_filter( 'auto_update_theme', '__return_false' );
@walterebert
walterebert / functions.php
Last active November 10, 2015 10:18
WordPress snippet: Unregister common taxonomies
<?php
function my_unregister_taxonomies()
{
unregister_taxonomy_for_object_type( 'category', 'post' );
unregister_taxonomy_for_object_type( 'category', 'pages' );
unregister_taxonomy_for_object_type( 'post_tag', 'pages' );
}
add_action( 'init', 'my_unregister_taxonomies' );