Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
Created July 14, 2023 10:09
Show Gist options
  • Save danielcharrua/2b1633d4d4bd99d3e54f7de93365e113 to your computer and use it in GitHub Desktop.
Save danielcharrua/2b1633d4d4bd99d3e54f7de93365e113 to your computer and use it in GitHub Desktop.
Replace social icon from social icon block on WordPress
<?php
/*
* Replace social icon from social icon block on WordPress.
* In this case we are replacing the wordpress icon for a custom svg one.
*/
add_filter(
'render_block',
function( $block_content, $block ) {
if ( 'core/social-link' === $block['blockName'] && 'wordpress' === $block['attrs']['service'] ) {
$icon = '<svg width="24" height="24" viewBox="0 0 24 24" version="1.1">
<path d="M20.9,4.16l-.08,.71C14.83,1.48,7.57,1.22,1.35,4.17v-.03C3.98,2.19,7.03,.88,10.25,.31c.28-.05,.54-.08,.81-.11,3.34-.46,6.74-.12,9.92,1,.04,.99,.01,1.97-.08,2.95Z" fill="#4897d2"/>
<path d="M1.35,4.14s-.06,.04-.09,.07c.03-.01,.06-.03,.09-.04v-.03Z" fill="#9057a3"/>
<path d="M11.06,.2c-.27,.04-.54,.07-.81,.11C7.03,.88,3.98,2.19,1.35,4.14c-.09-.97-.12-1.95-.08-2.92C4.41,.11,7.76-.24,11.06,.2Z" fill="#9057a3"/>
<path class="cls-3" d="M10.41,2.13c-3.13,0-6.23,.7-9.06,2.04-.03,.01-.06,.02-.09,.04-.43,.21-.85,.42-1.26,.66,.37,2.85,1.32,5.6,2.79,8.08l.93-7.59s.02-.08,.05-.11c.03-.03,.08-.05,.12-.05h1.8c.1,0,.15,.05,.15,.16l-.42,3.4s.02,.07,.06,.07h2.4s.03,0,.05-.02c.01-.01,.02-.03,.02-.05l.42-3.4s.03-.08,.06-.11c.03-.03,.07-.05,.11-.05h1.82s.08,.02,.1,.05c.03,.03,.04,.07,.03,.11l-1.09,8.9s-.03,.08-.06,.11c-.03,.03-.07,.05-.11,.05h-1.82s-.08-.02-.11-.05c-.03-.03-.04-.07-.03-.11l.42-3.5s0-.07-.05-.07h-2.38s-.06,.02-.08,.07l-.57,4.75c1.62,1.99,3.59,3.67,5.81,4.96,2.43-1.4,4.56-3.28,6.25-5.52l-.93-.94c-.07,.04-.12,.09-.19,.13-.58,.29-1.23,.44-1.88,.43-.83,.04-1.63-.24-2.25-.79-.57-.56-.87-1.34-.83-2.13,0-.17,0-.34,.03-.51l.33-2.63c.07-.64,.29-1.24,.65-1.77,.35-.51,.82-.92,1.37-1.2,.58-.29,1.22-.44,1.86-.43,.57-.01,1.13,.11,1.65,.36,.45,.22,.82,.57,1.07,1.01,.26,.46,.39,.99,.37,1.52,0,.17,0,.34-.03,.51l-.32,2.63c-.04,.34-.12,.67-.23,.99l.66,.66s.04,.04,.08,.07c1.45-2.44,2.39-5.16,2.75-7.98-3.18-1.8-6.77-2.75-10.42-2.74Z"/>
<path class="cls-3" d="M13.55,7.38c-.29,.29-.47,.68-.51,1.09l-.33,2.73c0,.09-.01,.18-.01,.26-.02,.33,.09,.66,.32,.91,.23,.23,.54,.35,.86,.33,.39,0,.77-.14,1.05-.42,.29-.29,.47-.68,.51-1.09l.34-2.73c.01-.08,.01-.16,.01-.24,.02-.34-.1-.67-.32-.92-.23-.23-.55-.36-.88-.34-.39,0-.76,.14-1.03,.41Z"/>
</svg>';
$before = explode( '<svg', $block_content );
$after = explode( '</svg>', $before[1] );
$block_content = $before[0] . $icon . $after[1];
}
return $block_content;
},
10,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment