GitHub Code Viewer 2 is a plugin for wordpress that will automatically pull a file from github and place into any post using a shortcode [github_cv url=‘$url’]. It caches the code locally (in db), so it’s quite fast and can be even faster when combined with wp_super_cache or w3c_total_cache. It will re-request the code from github every 24 hours (by default, but it’s configurable) so the code in your post will always remain up to date. It is a heavily modified version of the original GitHub Code Viewer plugin written by Matt Curry http://www.pseudocoder.com.
- Upload `GitHub_Code_Viewer.php` to the `/wp-content/plugins/` directory (or install through the ‘add new’ functionality in wordpress)
- Activate the plugin through the ‘Plugins’ menu in WordPress
- Use the shortcode [github_cv url=’<URL TO FILE ON GITHUB>’] in your post.
- Find a given file on github you want to include in a blog post / page.
- Grab the url to this page.
- Place this code in your post [github_cv url=’<THE URL>’] where you want the file to appear.
- Optionally provide a different TTL (time to live), default is ’1 day’. This will be passed to str_to_time, so pass in whatever it would accept. This would look like: [github_cv url=’<URL>’ ttl=‘1 week’]
- Optionally surround the code with a syntax highlighter. ColorCoder is a good one which uses the geshi library.