Created
March 8, 2024 08:55
-
-
Save anatolinicolae/440fb1dcad69bc5e6a8c9ce8de66d586 to your computer and use it in GitHub Desktop.
Content inclusion shortcode example
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 | |
/** | |
* 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