Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Last active July 5, 2020 16:57
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 damiencarbery/a2d3bf9516fde77a0aefa461ebda9820 to your computer and use it in GitHub Desktop.
Save damiencarbery/a2d3bf9516fde77a0aefa461ebda9820 to your computer and use it in GitHub Desktop.
Append private page to content - Append a specified page to post or page content. https://www.damiencarbery.com/2020/07/append-private-page-to-content/
<?php
/*
Plugin Name: Append content to all pages and posts
Plugin URI: https://www.damiencarbery.com/2020/07/append-content-to-all-pages-and-posts/
Description: Append a specified (private) page to all pages and posts.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.1
*/
// Append private page to a page or post.
// This should work on all themes.
add_filter( 'the_content', 'dcwd_append_page_to_content' );
function dcwd_append_page_to_content( $content ) {
$appended_content_page_id = 1820; // ID of the private page.
if ( is_singular() && is_main_query() ) {
// Do not add the content to itself!
if ( get_the_ID() == $appended_content_page_id ) {
return $content;
}
// You may add additional checks here e.g. exclude certain posts or pages.
return $content . get_post( $appended_content_page_id )->post_content;
}
return $content;
}
// If you have a Genesis theme you can use this option instead of 'the_content' filter above.
add_action( 'genesis_after_entry_content', 'dcwd_add_page_after_content' );
function dcwd_add_page_after_content( $content ) {
$appended_content_page_id = 1820; // ID of the private page.
if ( is_singular() && is_main_query() ) {
// Do not add the content to itself!
if ( get_the_ID() != $appended_content_page_id ) {
echo get_post( $appended_content_page_id )->post_content;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment