when a shortcode is defined, he has to return HTML output. then to allow the theme to customise data presentation, you can do something like that :
add_shortcode("form_step_2", function ($attr, $content, $tag) {
// preparing data
//...
// result to display
$template_name = "form/step_2";
// search the file wp-content/themes/twentytwenty/my_plugin/form/step_2.php
$template = locate_template("my_plugin/$template_name.php");
// if the file doesn't exist in the theme
if ("" === $template) {
// use the plugin file wp-content/plugins/my_plugin/templates/form/step_2.php
$template = __DIR__ . "/templates/$template_name.php";
}
ob_start();
require $template;
$output = ob_get_clean();
return $output;
});
Related Posts:
- Custom user roles
- How to create a custom search for custom post type?
- what is the correct way to compare dates in a WP query_posts meta_query
- Possible to hide Custom Post Type UI/Menu from specific User Roles?
- How do you use a CPT as the default home page?
- WordPress dashboard, viewing CPT results in 504
- Displaying Custom Post Types In “At A Glance” Meta Box
- How to set a default format for a custom post type?
- WordPress Custom Post Types with a page as a parent?
- How to Make an admin_notices Message That Disappears Once the User Leaves That Particular Page?
- Custom Taxonomy with Custom Post Type Finds No Posts
- Delete all the custom post types when deleting user
- Correct way to use a form to to filter custom posts by taxonomy terms?
- Showing current taxonomy terms
- White screen error for a custom theme
- automatically create taxonomy with same name as post title
- How can I remove categories in menu in custom post type?
- Search results ordered by custom post types are not grouped
- saving custom post type data to different table in wordpress
- Query post types with multiple keys
- Remove POST_TYPE from custom post type permalink
- Adding help information to custom post edit page
- Restrict categories to a custom post type
- Get all posts WHERE custom_field is LIKE value
- Programmatically adding posts
- How does the $post_type global variable work?
- Sending an email when a CPT is saved/updated (NOT when it’s created)
- Custom Post Type, Saving Multiple Checkboxes
- Get rewrite slug of custom post type in template
- Delete link on single-custom.php with redirection
- Getting rid of /my_custom_post_type/ in the single view URL
- Custom Post Type – List all attachments on Edit Screen
- Custom Page that comes with preloaded content for the user
- How to customize a permalink (URL) structure?
- How to integrate video slide using custom post types?
- will post_id ever change? Can I safely use post_id for custom queries?
- Is it possible to create relational metabox values in a custom post?
- Custom Post Type Query for Sidebar Doesn’t Work on Front Page
- Time based access control of custom post types – what is good approach?
- Show titles, date of all posts on single category page
- Update postmeta Parent when post_status child change
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- A form that can save/edit after first input
- Send notification to the admin when new custom post is submitted
- How to produce a sub-page-system in WordPress
- don’t publish custom post type post if a meta data field isn’t valid
- Detect inside a custom query the kind of post type to assign custom classes
- How do you make a custom post type items automatically delete items 3 months after publication?
- custom post data – how to
- Custom URL redirect in WP
- Add an Outside Wrapper to my Header and Make it Full Width
- attach CPT data to a taxonomy
- Creating a non-hierarchical Taxonomy that behaves like categories
- How to Create a Separate Page for Blog Posts in WordPress
- Separate Content from gallery (custom post type)
- Custom Post type content within a slider
- Add custom columns in custom post type browse page
- Displaying a custom post type using get_template_part into a specific layout
- Displaying a list of Contacts
- WordPress as a frontend website for iOS app [closed]
- How can I make custom static widgets/areas on my homepage?
- Displaying One Custom Post Type’s Content On Single Post of Another Custom Post Type
- How to hide a custom field from admin?
- Get terms for a specfic post from multiple taxonomies in custom post type
- Add Class After 4th Post
- cannot achieve this structure (custom posts VS categories VS ??)
- Is it possible to have hierarchical taxonomy and hierarchical custom post types in one permalink?
- how to use custom post types collectively integrated with each other
- Why doesnt my tag page populate with this custom post type?
- Home page is getting current-menu-item even if it’s not home
- Setting Parent Page to Post
- Question about link two types of data in wordpress
- allowing custom user role to access custom post type in wordpress admin
- Slow CPT in backend
- Custom Post Type and Structure Question
- Create API’s for custom-post types & custom queries using REST or Graphql
- custom post type and user post count shortcode
- Metabox collapsed by default
- My post loop needs to have 8 different post templates
- pricefilter without WooCommerce
- Convert attribute woocommerce terms (taxonomy terms) in posts of custom post type
- Update/publish custom post type with jQuery?
- Is there a best practice, or typical way to do AJAX updating for data on a custom admin screen or post.php?
- Link two different post using there post_id in post meta
- Help with Travel Guide Setup
- Child Theme problems
- How do I get a nested query to only display content that the main query outputed
- Add category slug as class attribute in a link array
- Sort by Custom Post Type (Multiple Loop)
- Delete attachment with post
- Get link for feed of specific post type AND taxonomy
- Displaying information from Custom Fields in template with Types?
- Change column of row action (Quick Edit) links in WP_List_Table
- 2 language CPT content
- Allow certain part of a page to be easily updated for client?
- Custom post type – columns order
- custom post-type query just returns two posts
- Exposing custom fields to the user in custom type post
- display posts, pages and custom post types from another wordpress site
- How to develop Knowledge center in WordPress Website