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
- Why do templates contain so many PHP tag pairs?
- How do I use Shortcodes inside of HTML tags?
- 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
- WordPress theme & site not loading after moving files
- Creating a WordPress shortcode
- How do I hardcode a WordPress shortcode into my theme?
- has_shortcode() – how to detect nested shortcode
- How do I turn a shortcode into PHP code?
- Password protecting content in custom template
- How to return a foreach inside a shortcode
- Placing raw HTML inside a WordPress shortcode
- Shortcode content output but not in correct place
- An unwanted inline style is added to my body tag
- How to display posts by current user in a drop down
- Mass update excerpt
- Colon is Missing In My Website Url in WordPress
- Change title only in dynamic page
- Pass php dynamic variable to shortcode
- wordpress 4.4 self hosted video (html5) doesn’t show
- do_shortcode with custom field
- Shortcode to show the code
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Use WordPress function in php file
- Multiple do_shortcode in page template
- Add filter multiple times using only one master function
- get_posts works in the page template but not in a shortcode
- How can I include shortcodes within PHP?
- $wpdb returns duplicate posts
- Syntax error in a shortcode function
- Shortcode to find and replace URL
- Help with WordPress function inside a shortcode
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Removing WordPress Footer -without access to PHP code?
- Create page template via functions.php?
- Short code template + ajax
- WordPress shortcode returns the data before
- Shortcode to embed Edit Account form not working
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- how to display this functions?
- is_page_template showing partial results
- Adding regular php file to site
- Post repeated when opening in overlay, how do I solve this? [closed]
- Split shortcodes to array of shortcodes
- PHP error with a shortcode: “no suitable wrapper” for file_get_contents
- How to make a conditional statement within $output in shortcodes.php?
- Shortcode for a Series of Elevating Image Files, Excluding a Range?
- Shortcode won’t execute
- pass html code to worpdress
- Shortcode displaying at the top of the page [duplicate]
- AJAX function not working [closed]
- Can ‘Custom Field’ data be inserted into this Short Code?
- Getting a WordPress tag to print inside of a traditional php echo
- How to exclude labels from certain categories in a shortcode?
- Set document title through shortcode plugin
- Prevent header and footer from loading on specific pages with template or plugin
- Shortcode in Shortcode/HTML Graphics and Pictures
- Why is the current page loaded in the pop-up window and not the specified one?
- How to search order using database frontend short code WordPress
- How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
- Display metabox galleries on specific page template in admin editor
- Not able to remove caption shortcode from the content
- Display WordPress archive template page in 3 columns and not 1 column [closed]
- Run do_shortcode on php template using JS function
- How to hardcode header and footer in WP?
- Get title of page containing post grid within the posts
- Shortcodes not processing inside post content
- Gravity Forms: How to add PHP function to confirmation conditional shortcode?
- wpdb->query returns different value to phpMyAdmin
- I want to hide “sold by” on certain pages with id page 43
- How to add a PHP scripts into WordPress
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- Replacing entire tag with shortcode – JavaScript [duplicate]
- If is_page elseif is_page not working like I want it to
- Get posts by id using shortcode
- Shortcode just with a php code
- missing admin bar and widget in a template
- My own theme’s custom widget areas are not working
- Custom fields changes the formatting of metabox input
- Contact form field in wordpress menu
- Serializing URL via wp add_shortcode to auto select from option list onload
- php string inside shortcode does not work
- Limit the number of successful logins
- How to call a certain object/menubar in a PHP file
- Shortcodes (with a space) added to php Sample
- How can I put a custom field as the link of a button shortcode?
- Custom field within shortcode
- why is markup routinely placed in functions in wordpress?
- Problem using explode inside add_shortcode() callback funciton [closed]
- Php inside the shortcode is getting commented
- Display Current Time using shortcode
- How to create shortcode of this PHP code
- Display terms on product page with shotrcode
- Redirect loop upon installation of my plugin
- Custom plugin with shortcode not working
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)