Skip to content

Instantly share code, notes, and snippets.

@anatolinicolae
Created March 8, 2024 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anatolinicolae/440fb1dcad69bc5e6a8c9ce8de66d586 to your computer and use it in GitHub Desktop.
Save anatolinicolae/440fb1dcad69bc5e6a8c9ce8de66d586 to your computer and use it in GitHub Desktop.
Content inclusion shortcode example
<?php
/**
* Plugin Name: Content Shortcode
**/
add_shortcode('content', function ($atts) {
extract(shortcode_atts([
'slug' => null,
'post_type' => 'post',
], $atts));
$post = get_page_by_path($slug, OBJECT, $post_type);
if (!$post) {
return sprintf(__('No content found for slug `%s` in `%s` post type.', 'your__text_domain'), $slug, $post_type);
}
return apply_filters('the_content', $post->post_content);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment