Synchronizing WordPress posts with Github

I treat my WordPress blog as my “digital home” – THE place to collect my thoughts, describe projects, and publish ideas.

It works very well for writing, but my coding projects feel better on Github. They also appreciate the documentation and descriptions I attach to them.

Over time, my projects would get out of sync with their WordPress counterparts. I would add new features, change behavior or describe new use cases and would have to manually change that in WordPress, which I naturally forgot to do.

I wrote this simple snippet to embed any Github .md file inside WordPress posts or pages. Content would be refreshed from Github every hour and displays inside the post like it was written on WordPress.

Here is an example page. Almost the entire content is from the associated

How to sync your WordPress posts with any markdown file on Github

  1. Use the attached code to introduce the GitHub markdown handler to your WordPress blog. Remember to also attach Parsedown.php!
  2. Create an amazing project solving the world’s most pressing problem, write a .md file describing it
  3. Copy the URL to Github markdown file
  4. Paste it to WordPress block editor, and see how it turns into the content from the file.

Here is the code:

// Drop this in functions.php or your plugin.
// You NEED to have Parsedown.php also :
__NAMESPACE__ . '\artpi_github_markdown_handler'
function artpi_github_markdown_handler( $matches, $attr, $url, $rawattr ) {
$url = str_replace(
[ '', '/blob' ],
[ '', '' ],
$transient_key = 'gh_' . md5( $url );
$content = get_transient( $transient_key );
if ( ! $content ) {
$request = wp_remote_get( $url );
if ( is_wp_error( $request ) ) {
return false;
$content = wp_remote_retrieve_body( $request );
if( ! $content ) {
return false;
require_once __DIR__ . '/Parsedown.php'; // You will need to download Parsedown
$md_parser = new \Parsedown();
$content = $md_parser->text( $content );
if( ! $content ) {
return false;
$content = "<div class='github_readme_md'>$content</div>";
set_transient( $transient_key, $content, 3600 );
return apply_filters( 'embed_github_readme_md', $content, $matches, $attr, $url, $rawattr );
view raw functions.php hosted with ❤ by GitHub

Leave a Reply