-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Once activated the plugin creates a custom post type, taxonomy, and shortcode all of which are called "includes."
-
[includes slug="post-slug"]
Displays post content from the Includes post type, and optionally all posts and pages -
[includes code slug="post-slug"]
Displays code content from the Includes post type -
[includes category="category-slug"]
Displays post content based on the category slug
The [includes]
shortcode requires either the slug
, or category
attributes for the shortcode to function property.
When the category
attribute is used two extra attributes can be applied: orderby
and order
.
Category attribute: orderby
none | No order
ID | Order by post id
date | Order by published date
title | Order by post title
slug | Order by post slug
rand | Randomize order
modified | Order by modified date
**Category attribute:** order
desc | Descending order ( default )
asc | Ascending Order
In the left WP Admin area menu select the "Includes" menu, then click the "Settings" link to open plugin settings.
- Enable shortcode viewer: Uses an empty template to view/test Includes
- Disable to use the your themes default page template view/test Includes
- Enable includes shortcode field(s) on Includes post type view
- Adds input fields to quick access the shortcode when viewing saved Includes
- Enable includes shortcode field(s) on category term pages
- Helpful if you use categories, does the same as above but on the Includes term pages
- Enable shortcode widget - a custom widget that renders shortcodes
- Add shortcode(s) to classic widgets. Renders shortcode content in block widgets
- Enable code editor and allow the Includes shortcode to render saved code
- Only enable if needed (allows CSS, PHP, JavaScript, etc)
- Allow "slugs" from posts and pages to be used by the Includes shortcode
- If used, test to ensure included content works as expected
- Allow post and page titles to render shortcodes
- Only enable if needed, requires extra resources
- Allow menus to render shortcodes
- Only enable if needed, requires extra resources
- Allow widgets to render shortcodes
- Only enable if needed, requires extra resources
The above 4 "other default disabled features" will consume more PHP memory, while minor it is still more. The more features that get enabled, the more memory that PHP will use. Some hosting providers, themes, and other plugins sometimes reach PHP memory limits when using these features. Use them sparingly.
Includes within Includes works when stacking one level deep in direct line ( parent -> child or child -> parent ). In rare cases, stacking Includes can cause issues with some themes and may consume more memory than your host provides - stack only when needed!
A typical use case would be injecting html blocks into to a page to complete the document. For example, Includes for an opt-in form ( the child ), is included within a homepage Include ( the parent ). The parents Includes shortcode is then added to the actual published homepage post - and not another Include. This is a simple child -> parent stack.
Keeping the example in mind above, an incorrect usage example would be adding another child Include inside the opt-in form Include. Stacked together this would create child->child->parent, which the Plugin will not render.
The parent Include can include multiple child Includes, as long as the child Includes are not stacked within each other.
The Includes plugin uses YahnisElsts/plugin-update-checker to allow updates to work like any other WordPress plugin - other than it updates from GitHub instead of the official WordPress repo.
Running npm run version
automatically populates the updates.json file. Plugin update checker reads this file to check if an update is pending.
When previewing an Include a custom empty template is used to display the content - this feature can be enabled and disabled within settings. The preview is only viewable to logged in administrators. The purpose of the blank template is to show off an example of saved Includes to ensure the content works as expected.
Advanced users can override the default template by creating the file template-parts/includes-preview.php
. Once defined the plugin will automatically use that template to preview saved Includes.
The preview template comes with two action hooks before and after content display.
- Before content hook:
do_action('includes_before_content');
- After content hook:
do_action('includes_after_content');
Example of opening a container, row, and column before the included content
/**
* Any Custom Content Before Includes Post Type Content
*/
function includes_before_content(): void {
$html = '<div class="container">';
$html .= '<div class="row">';
$html .= '<div class="col">';
return $html;
}
add_action( 'includes_before_content', 'includes_before_content' );
Example of closing a column, row and container after the included content
/**
* Any Custom Content After Includes Post Type Content
*/
function includes_after_content(): void {
$html = '</div><!-- .col -->';
$html = '</div><!-- .row -->';
$html .= '</div><!-- .container -->';
return $html;
}
add_action( 'includes_after_content', 'includes_after_content' );