Shortcode with a custom output template:
You could try the following shortcode demo:
/**
* The shortcode [history_timeline] with a custom output template.
*/
add_shortcode( 'history_timeline', function( $atts = array(), $content="" )
{
ob_start();
if ( '' == locate_template( 'templates/timeline.php', TRUE ) )
include( plugin_dir_path( __FILE__ ) . 'templates/timeline.php' );
$html = ob_get_clean();
return $html;
});
where the shortcode is [history_timeline]
and
if ( '' == locate_template( 'templates/timeline.php', TRUE ) )
include( plugin_dir_path( __FILE__ ) . 'templates/timeline.php' );
means:
-
If
/wp-content/themes/MYTHEME/templates/timeline.php
is located, then it will be automatically loaded. -
Else:
/wp-content/plugins/history-timeline/templates/timeline.php
is loaded.
where we assume that __FILE__
is in the history-timeline
root directory.
Related Posts:
- Looking for WordPress System Diagrams
- How can I load a page template from a plugin?
- Overwrite theme file from plugin
- How to control output of custom post type without modifying theme?
- When is it appropriate to put functions on page template vs. functions.php?
- Filter to change the content of 404 page
- How to properly use a hook to create template for custom product type in a plugin such as Woocommerce? [closed]
- How to check active theme is parent or child wordpress
- WordPress removing data attributes for scheduled post
- Is there a way to loop through a shortcode datasource to create a table?
- creating custom archive template within plugin for custom post type using archive_template filter
- Where to call wp_enqueue_script in a plugin with custom template?
- Can Page Templates be Applied to Archive and Post Templates?
- ORDER BY wp_post custom column name in wp_query
- Create a free scripts and styles template within a plugin
- How can I turn a custom wordpress page into a product page?
- Plugin templates vs Parent Theme
- How to make “upgrade safe” theme for a plugin?
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- How to create templates for a custom module to show on the front end within my theme?
- Why aren’t some plugin styles loading when I load a template?
- Plugin custom post template; without overriding all posts
- Best way to distribute templates and code accross multiple wordpress sites?
- Load php file with jquery in single.php
- Overriding the template files using a plugin for all themes
- How do I use a plugin to swap out the template file for a custom post type?
- Javascript not being loaded only in custom taxonomy template
- Add new header/footer on landing page with plugin
- Use a page as a template for a custom post type
- Page template compatibility with different themes
- How to set custom homepage via a plugin
- Template file structure , wordpress hook for altering the template
- Displaying External Data – Not Posts
- Use different archive template for plugin
- How to display custom taxonomy and terms using/creating plugin template
- How to check during “pre_get_posts” if WP performing default query for specific custom template?
- WP Job Manager – Show recent jobs as cards
- Help interpreting @wordpress/create-block-tutorial-template usage error
- What is the advantage of using wp_mail?
- Plugin directory “Last Updated” not changed after initial commit?
- Calling the widget id of a mult-instance widget from inside the widget?
- What is the recommended way to create plugin administration forms?
- Do I need to call do_action in my plugin?
- Fatal error: Call to undefined function wp_mail()
- Does WordPress have an Browser Agent?
- How Do I Load My Action Earlier Enough?
- I can’t find where a hook is being defined in a plugin – Easy Digital Downloads
- Filter on the_content ignores shortcodes
- Custom theme sufficient or custom plugin neccessary for this feature set?
- Replacing WordPress menu functionality with a plugin
- Database for development
- PHP library that can merge stylesheet with inline style [closed]
- How to create multiple Gutenberg blocks in one plugin
- How to disable reCaptcha v3 except on Contact Form 7 pages?
- How to get color name in PanelColorSettings in custom Gutenberg block?
- Fetching the value of forms in WordPress AJAX
- Cannot redeclare function error on the same line
- How to add setting section in custom post type [closed]
- Get Current Menu Location inside Nav_Walker
- Append country to ‘pretty’ url but serve same page
- Where to add hooks in a class
- Insert terms for custom taxonomy on plugin activation, or each page load (init hook)
- Adding a brand column to WooCommerce Products
- Custom GET Parameters In Plugin’s Admin Page
- Adding option to Gallery shortcode
- WordPress Search filter to remove possible script injections
- Mixing and Matching – Custom templates in a WordPress plugin
- Open Graph Object Debugger & url parameters – Page Not Found result
- random code at the end of file after plugin upload
- How Can I add Fields in wp-option table?
- Where do I put my add_action(… and add_filter(… and do I need to remove them?
- Can’t find where to modify attrbitutes
- ajax recursive calls on wordpress returning answers outsite the function scope
- Custom Empty Results page for my Custom Post Type
- Add Password Generator on password protected page
- WordPress pages are not published due to External database connection with WPDB class
- How to optimize multiple insert into wordpress database
- How to add custom options for plugin into the add post screen – like yoast seo
- How to find where an object first instantiatiation
- Clean way to initialize plugin in newly-added site when plugin has been network activated?
- Get coordinates of selected area to use in image maps [closed]
- Can I attach a plugin via my add_filter callback contents?
- How to trigger selected option from a clic. (variation product woocommerce)
- WordPress Favicon not Working For Images/Videos/PDFs
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- Show username only if logged in in a else no directly name
- Conditionally check if page is using template from plugin directory
- plugin css is not being applied to the page
- How to save multiple values in custom post type from front end to back end
- Yoast and another plugin
- Headers already sent on custom plugin (Export function)
- Insert Data into Database
- Handle changed Woocommerce function
- Making Woocommerce optimized for more than 500k products
- wp_enqueue_style don’t register all google fonts
- API WordPress is Limited? Return False
- Add placeholder into contact form 7 recaptcha text field
- To remove rendering of menus and header, plugin or theme?
- Generating Multiple Divi Pages from Database
- Is it smart to require_once wp-admin/includes/plugin.php when you need only one function from it