Something I forgot in my previous comment was that shortcodes return content, both the suggested include
and my alternative get_template_part
will directly output the content (which is what you are seeing with the content appearing at the top of your page instead of where the shortcode is called). To counteract this we must use output buffering.
Define the shortcode in your functions.php (or your site’s site-specific functions file).
function my_form_shortcode() {
ob_start();
get_template_part('my_form_template');
return ob_get_clean();
}
add_shortcode( 'my_form_shortcode', 'my_form_shortcode' );
Then in your theme folder you need a file called my_form_template.php
which will be loaded anywhere you place the shortcode.
Related Posts:
- Is there a way to parse shortcodes in PHP?
- Placing the_content inside shortcode not working
- Create dynamic content from one WP page to multiple other pages
- To close or not to close php
- How to manually fix the WordPress gallery code using PHP in functions.php?
- How does printf( __( ) ); work?
- Encode text string being appended as query to URL [closed]
- Why do templates contain so many PHP tag pairs?
- How do I use Shortcodes inside of HTML tags?
- Displaying a WooCommerce product via PHP
- Shortcode to insert
- What exactly does “Posts page” do in WordPress?
- Check if a menu is empty?
- Static Frontpage Pagination – Custom loop
- Get the php template file from other theme folder
- Shortcode putting html such as
- Display sorting options dropdown when using WooCommerce product category shortcode
- Retrieve multiple values passed to a single attribute in a shortcode
- WordPress Template Engine?
- WordPress Shortcode and Dynamic CSS
- How to have a custom display for both woocommerce archive and product-category pages? [closed]
- ob_get_clean returns empty string, ob_get_flush outputs string
- Display a text message if the shortcode is not found?
- Export User Info to CSV from Front End
- wp_remote_get returns an error for valid URL
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- Shortcode created to check language not works
- On this day PHP code
- How to loop over custom fields in a page template?
- Blank on static home page?
- How to return a string that has a variable inside in a shortcode?
- Run shortcode at certain resolution
- Using Echo in ShortCode – Stuck
- Passing a shortcode attribute to a sub-function
- How to create shortcodes that pull custom field data from general settings
- post meta value as shortcode parameter
- WordPress theme & site not loading after moving files
- How to protect own PHP code from WordPress updates
- Add/echo div with Analytics-Code to function in functions.php
- Adjust the results quantity for Search Results page pagination
- Creating a WordPress shortcode
- Multiple do_shortcode($content) within one shortcode
- Adding Image Count to Multigallery
- the_title() & the_content() are retrieving Post details inside a Page, after calling a shortcode
- Exclude pages with certain template from wp_list_pages
- Get list of shortcodes from content
- Audio tags around Mp3 URL in content
- How do I hardcode a WordPress shortcode into my theme?
- Loading page template into shortcode
- Use Timber/Twig to pull an image by image ID [closed]
- Categories Template Assistance
- My shortcode is showing up twice
- How to add Shortcode (font awesome) in widget title?
- has_shortcode() – how to detect nested shortcode
- How to return multiples lines in a shortcode?
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- How can I default to all WordPress roles when parameter is not included in shortcode?
- WordPress menu deletes when trying to add a hook
- Is it possible to use the featured image of a page as a css background without inlining?
- PHP contact form returns warning in text widget [closed]
- Unable to set right time in admin and frontend template
- Easiest way to show total number of subpages
- How to find the output of contact form 7 shortcode? [closed]
- Switching between custom templates in a post type of the admin menu
- Use template for posts with a particular category grandparent
- Wrap each shortcode in array to div
- How do i get (unique) page name?
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- Can A Shortcode Get HTML/Text From Content And Return It Twice With Added HTML?
- Recent post display using shortcode
- Browser title script ignoring is_page /else conditional [closed]
- How do I turn a shortcode into PHP code?
- Blank space at beginning of tag?
- Nested shortCode functions in the functions.php file
- Put php variable in shortcode
- Link to file in plugin directory from wordpress template?
- get_page_by_title with an apostrophe in variable
- Need to turn this php into WP shortcode
- Password protecting content in custom template
- Making Quote Plugin more efficient
- Autogenerate shortcodes from an array of strings
- How to limit the content coming from wordpress shortcodes?
- How to override wp-admin styling
- How to return a foreach inside a shortcode
- Placing raw HTML inside a WordPress shortcode
- How do I add text in a shortcode?
- Add a Second Menu to a theme that only support 1 menu
- How to Insert Shortcodes into Theme?
- Custom excerpt function re-factoring
- How can I get content inside one shortcode to another shortcode?
- Template part inside shortcode, unexpected reult
- Inject PHP code into “sidebar-content” – code before my WooCommerce sidebar widget?
- Shortcode Inside Class Not Working
- custom shortcode will not display the wrapped content
- Shortcode content output but not in correct place
- How to display user nickname (not display name) in PHP template?
- Custom Template 404 for specific custom post type
- is_page “range” for if statement?
- An unwanted inline style is added to my body tag
- How can I generate random numbers inside my shortcodes on each implementation?