Back to Support Content and Media Blocks Embed Blocks Gist

Gist

Gist is a way to share snippets and pastes with others. All gists are git repositories, so they are automatically versioned, forkable and usable as a git repository.

Embedding with a URL

To embed a Gist, copy the gist’s URL from your web browser’s address bar while viewing the gist.

Screenshot showing a GitHub Gist URL in the browser's address bar.
Gist URL in browser’s address bar.

Paste it on a line by itself in the editor. Make sure that the Gist URL is not hyperlinked.

We take care of the rest! The gist will look something like this:

<?php
$query_args = array(
'foo' => 'bar',
'apple' => 'orange',
'posts_per_page' => 50,
'offset' => 0,
);
$some_posts = new WP_Query( $query_args );
while ( $some_posts->have_posts() ) {
/*
* Do some stuff here
*/
// Get more posts
$query_args['offset'] = $query_args['offset'] + $query_args['posts_per_page'];
$some_posts = new WP_Query( $query_args );
}
view raw gistfile1.aw hosted with ❤ by GitHub

Embedding with a Shortcode

You can also embed a gist by using a shortcode. You can do this by first copying the gist URL from your web browser’s address bar while viewing the gist.

Screenshot showing a GitHub Gist URL in the browser's address bar.

Then create a shortcode using the format below. Be sure to replace the URL listed here with the URL of your gist, and the code is on a line by itself.

[gist https://gist.github.com/Viper007Bond/2314628 /]

You can add a shortcode to any page or post using a shortcode block.

<?php
$query_args = array(
'foo' => 'bar',
'apple' => 'orange',
'posts_per_page' => 50,
'offset' => 0,
);
$some_posts = new WP_Query( $query_args );
while ( $some_posts->have_posts() ) {
/*
* Do some stuff here
*/
// Get more posts
$query_args['offset'] = $query_args['offset'] + $query_args['posts_per_page'];
$some_posts = new WP_Query( $query_args );
}
view raw gistfile1.aw hosted with ❤ by GitHub

You can also create a gist shortcode using just the gist ID copied from the Gist URL like this:

[gist]2314628[/gist]

Screenshot showing a GitHub Gist ID in the browser's address bar.

Troubleshooting

For information about troubleshooting Gist embeds, take a look at our Troubleshooting Embed Links doc.

Was this guide helpful for you?

Not quite what you're looking for? Get Help!

Copied to clipboard!