Skip to content

Instantly share code, notes, and snippets.

@EricTurner3
Created March 2, 2022 19:17
Show Gist options
  • Save EricTurner3/d124d1a0bae0cb2f7f58fde430e68e13 to your computer and use it in GitHub Desktop.
Save EricTurner3/d124d1a0bae0cb2f7f58fde430e68e13 to your computer and use it in GitHub Desktop.
Add emgithub embed to Wordpress
<?php
//Add this function to your /wp-content/themes/<yourtheme>/functions.php
//It uses emgithub.com to spawn an embed for your github code on a Wordpress Bloc
//Derived from https://crunchify.com/how-to-embed-and-share-github-gists-on-your-wordpress-blog/
// 2 Mar 2022
/**
*
* Example: https://github.com/EricTurner3/cybersecurity/blob/main/HackTheBox/challenges/forensics/redfailure/decrypt.cs
* Usage:
* [gh]https://github.com/EricTurner3/cybersecurity/blob/main/HackTheBox/challenges/forensics/redfailure/decrypt.cs[/gh]
* [gh url="https://github.com/EricTurner3/cybersecurity/blob/main/HackTheBox/challenges/forensics/redfailure/decrypt.cs" /]
*
* Can also modify other things like themes (see https://emgithub.com/ for full list)
* [gh style="atom-one-light"]https://github.com/EricTurner3/cybersecurity/blob/main/HackTheBox/challenges/forensics/redfailure/decrypt.cs[/gh]
*/
function add_emgithub_shortcode( $atts, $content = NULL ) {
extract( shortcode_atts( array(
'url' => '',
'style' => 'atom-one-light',
'showBorder' => 'on',
'showLineNumbers' => 'on',
'showFileMeta' => 'on',
'showCopy' => 'on',
'fetchFromJsDelivr' => 'on',
), $atts ) );
return sprintf('<script src="https://emgithub.com/embed.js?target=%s&style=%s&showBorder=%s&showLineNumbers=%s&showFileMeta=%s&showCopy=%s&fetchFromJsDelivr=%s"></script>',
$url ? trim(esc_attr($url)) : trim(esc_attr($content)),
$style, $showBorder, $showLineNumbers, $showFileMeta, $showCopy, $fetchFromJsDelivr
);
}
add_shortcode('gh', 'add_emgithub_shortcode');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment