Created
May 22, 2020 00:47
-
-
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.
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 | |
/** | |
* 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( ']]>', ']]>', $content ); | |
} | |
return $content; | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment