Skip to content

Instantly share code, notes, and snippets.

@runezero
runezero / social-bookmarks.php
Last active May 25, 2022 18:46
[Social icons shortcode] Display the social icons list with a shortcode #enfold
add_shortcode('dsm-social-icons', 'dsm_social_icons_shortcode');
function dsm_social_icons_shortcode() {
$social_args = array('outside'=>'ul', 'inside'=>'li', 'append' => '');
$social = avia_social_media_icons($social_args, false);
return $social;
}
@runezero
runezero / avia_breadcrumbs.php
Last active May 25, 2022 19:30
[Replace enfold breadcrumb with Yoast] Switches the Enfold breadcrumbs with the Yoast breadcrumbs for SEO #enfold
add_filter( 'avia_breadcrumbs', 'maybe_replace_avia_breadcrumbs', 100 );
/**
* Maybe replace the Avia breadcrumbs by Yoast breadrumbs
*
* @param string $breadcrumb HTML output for breadcrumbs
*
* @return string Breadcrumbs output
*/
@runezero
runezero / use_widgets_block_editor.php
Created May 25, 2022 14:50
[Switch to old widget editor] Switch the modern widget editor back to the classic view #wordpress
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
add_filter( 'use_widgets_block_editor', '__return_false' );
@runezero
runezero / phpmailer_init.php
Created May 25, 2022 14:49
[Set noreply as default mailer] Set the noreply email address as the default email sender for spam purposes #wordpress
add_action( 'phpmailer_init', 'set_mailer_smtp_from_address' );
function set_mailer_smtp_from_address($phpmailer)
{
$urlparts = parse_url(home_url());
$domain = $urlparts['host'];
$domain = str_replace('www.', '', $domain);
@runezero
runezero / init.php
Created May 25, 2022 14:48
[Add noindex if site in maintenance] Add noindex to the robots if the blog is nog public #wordpress
add_action( 'init', 'maybe_add_noindex_meta' );
function maybe_add_noindex_meta()
{
// If maintenance page is shown by Maintenance plugin
if(!is_user_logged_in()) {
if (get_option( 'blog_public' ) === '0') {
add_action('add_gg_analytics_code', function(){
@runezero
runezero / robots_txt.php
Created May 25, 2022 14:45
[Add sitemap to the Robots file] Add the sitemap to the robots.txt file for SEO #wordpress
add_action('plugins_loaded', function(){
add_filter( 'robots_txt', 'maybe_modify_robots_txt', 20, 2 );
}, 999);
/**
* Modify the robots.txt, if not present
*
* @param string $output The robots.txt output
* @param boolean Whether the site is considered "public".
*
@runezero
runezero / auto_core_update_send_email.php
Last active July 21, 2022 06:53
[Disable update and account mails] Disable all succesfull update mails and user registration emails #wordpress
add_filter( 'auto_core_update_send_email', 'disable_auto_core_updates', 10, 4);
add_filter( 'admin_email_check_interval', '__return_false' );
add_action( 'init', 'dev_disable_new_user_notifications' );
//Disable the updated feature notification emails
function disable_auto_core_updates( $send, $type, $core_update, $result ) {
if ( ! empty( $type ) && $type == 'success' ) {
return false;
}
@runezero
runezero / login_headerurl.php
Created May 25, 2022 14:17
[Change wp login page styling] Add a custom styling to the login page #wordpress
function wpdev_login_logo() { ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/logo.jpg);
height:85px;
width:150px;
background-size: 150px 85px;
background-repeat: no-repeat;
padding-bottom: 0px;
}
@runezero
runezero / template_redirect.php
Last active November 8, 2022 21:18
[Redirect from category] If on category page, redirect to the home page #wordpress
<?php
/* Register template redirect action callback 24-05-2019 */
add_action('template_redirect', 'code_remove_wp_archives');
/* Remove archives */
function code_remove_wp_archives(){
//If we are on category or tag (data and autheur is done via YoastSEO)
if( is_category() || is_tag() ) {
wp_redirect( home_url());
}
@runezero
runezero / upload_mimes.php
Created May 25, 2022 14:14
[Allow file type upload] Allow new file type uploads in the media library, multisites excluded #wordpress
add_filter( 'upload_mimes', 'allow_upload_new_mimes' );
function allow_upload_new_mimes( $mimes = array() ) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}