Something like the following should work:
function my_header() {
ob_start();
include(get_template_directory() .'/file.php';
$content = ob_get_clean();
return $content;
}
add_shortcode('include', 'my_header');
Related Posts:
- Using locate-template & shortcodes doesn’t appear to work
- How to extract the variables out from “add_shortcode” function?
- How to include any template using Shortcode fuction?
- Load templates, pass arguments, and render output from functions.php
- Creating mixture of shortcodes to use in the visual/text editor
- How to redirect to post if search results only returns one post
- How to display random users with avatars
- How to customize search result page title?
- Creating a table from shortcode avoiding wpautop for each row
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- Stripping shortcode from custom excerpt function
- Formatting post content to exclude gallery
- Shortcode with custom content attribute?
- Shortcode to insert menu in page body?
- Displaying a random user with a shortcode
- Passing HTML in WordPress Shortcode arguments
- Can I use require() function in a template file?
- How to set global variables in template page?
- Function to show only first instance of shortcode
- Make “sidebar template” the default template for new pages
- Retrieve post modified date for specific post by post ID
- Custom Shortcode, functions PHP WP_Query loop
- Super simple shortcode not working
- Attach parent category template to all subcategories
- Add class or ID to any WordPress function
- Display gallery on top before content
- List child pages of specific page using shortcode
- How to remove howdy dropdown menu content
- How to include local menu based on page id?
- Default Gallery Edit/Template Editable?
- How to get specified parent page title in my function
- Possible to display shortcode based on the category?
- Display post shortcode content in the sidebar?
- How to get the index number of the posts?
- Using shortcode content with nested shortcode
- Custom shortcodes not inserting into visual composer columns
- How to filter $content in shortcode function
- Functions For Calling Specific Elements
- Full page template function
- Adding a colorbutton in tinymce dialog with current api
- Display gallery on bottom after content
- Excerpts are not displayed by a shortcode on category pages
- WordPress Shortcode function display outside of widget
- check if the user is owner of current page
- shortcode help require
- wordpress use single ajax in place of multiple ajax requests in a smarter way
- Add Element as a Filter to the_content
- Use html inside shortcode function
- I have problems with loading javascripts
- Need print logo without any ID & class
- wp_nonce_field is breaking form for reasons unknown
- Define PHP variable from a seperate API if statement
- Visual Composer creating own shortcodes with vc_map() to return simple Image
- Function shortcode – Set Parameter
- Using multiple line variable inside a function?
- Echoing function into WordPress NextGen gallery
- attachment page template? only show attachments for current post?
- How to echo the value of an array element using a function via a shortcode
- Wp-query Order By problem
- How to parse a shortcode within a shortcode?
- Variables not showing in short code
- Image loading function not working on archive.php template
- Specify multiple categories for custom post template – FATAL ERROR
- How to create shortcode with html and php content?
- Shortcode question
- How to make a new function that includes a template
- Can I include a custom PHP function in a WordPress function?
- Shortcode to get featured image of specific id post
- Problem with shortcode inside a shortcode
- Need help making a short code work
- Display a list of random terms from custom taxonomy with shortcode
- the_date() and the_time() functions display actual date an time instead of published date and time
- Changing the HTML of notices in WooCommerce [closed]
- Probleme shortcode with list author
- Last updated posts shortcode in functions.php
- Shortcode to output category description by passing ID
- Display list of pages that contain a certain string within the slug
- HowTo: Add wrapper to columns shortcode?
- Shortcode Function – Can’t get anything else to return after running shortcode within shortcode
- Custom shortcode with do_shortcode and substr
- Newest comments first not working
- Retrieve a custom form field modified by a filter
- us states dropdown function and echo in theme template files
- Can I use a function to return HTML and the result of another function?
- How to pass a variable from a template page to the child theme functions.php
- Function the_content
- Expanding a function to call a plugin or show a link
- Allow the access over wp-login.php
- Trying to the deduce shortcode from a function
- How to display data from custom fields in my custom shortcode?
- Modify function Shortcode_atts
- Run function from parent on child site
- Shortcode Variations?
- Custom shortcode not being included in content paragraph [duplicate]
- How can i hide content if not friend in Buddypress? [closed]
- Which template file to edit to edit homepage in Mystile [closed]
- Make a PHP file with a function
- PHP error in shortcode [closed]
- My website is generating weired url parameters of paginated pages
- How to store page-{id}.php templates in custom folder