Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created May 22, 2020 00:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/84376bb44afabdfa9d93e83b0c87abb8 to your computer and use it in GitHub Desktop.
Save wpscholar/84376bb44afabdfa9d93e83b0c87abb8 to your computer and use it in GitHub Desktop.
A simple plugin providing a shortcode that will output the post content for a specific post ID.
<?php
/**
* Post Content Shortcode
*
* @package PostContentShortcode
* @author Micah Wood
* @copyright Copyright 2020 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
* @wordpress-plugin
* Plugin Name: Post Content Shortcode
* Plugin URI:
* Description: A simple [post_content] shortcode to show the content of a specific post.
* Version: 1.0
* Requires PHP: 5.6
* Requires at least: 5.0
* Author: Micah Wood
* Author URI: https://wpscholar.com
* Text Domain: post-content-shortcode
* Domain Path: /languages
* License: GPL V2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
add_action(
'init',
function () {
add_shortcode(
'post_content',
function ( $atts, $content = '' ) {
$atts = shortcode_atts( array( 'id' => 0 ), $atts );
$post = get_post( $atts['id'] );
if ( $post ) {
$content = get_the_content( null, false, $post );
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]&gt;', $content );
}
return $content;
}
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment