Created
March 2, 2022 19:17
Add emgithub embed to Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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