You can always use the output buffering to store the printing contents in a variable.
function return_get_template_part($slug, $name=null) {
ob_start();
get_template_part($slug, $name);
$content = ob_get_contents();
ob_end_clean();
return $content;
}
$content = return_get_template_part('content', 'page');
This would be most preferable to keep using the get_template_part() right now. An alternative would be to use locate_template() function but it would compromise the use the default templates.
Check implementation of get_template_part() and locate_template() you would understand.
Related Posts:
- When is get_template_part() preferable to simply using the template.php files?
- Variable use in get_template_part
- Unexpected results with conditionals inside template part
- Conditional get template part
- Does get_template_part() content gets parsed if it’s not executed?
- Get_template_part seems to be ignoring my template
- Blog template with different header to rest of site
- wordpress header leaks into body in a specific template
- What does is_page_template() compare against?
- Creating custom blog page template the right way
- How To Create A Paginated List Of All Categories On My Site?
- How to remove all styles for certain page template?
- Simplest way to add a second html editor to the post/page admin?
- How to consolidate multiple static page templates into one dynamic one?
- Capturing arbitrary semantic URL arguments
- How do I display the text inside the WP editor for a page with a custom template?
- What content should go in index.php?
- How can I dynamically load another page template to provide an alternate layout of the posts?
- get url page template
- Posts archive index pagination in a static page custom query
- How to remove a parent theme template from Quick Edit?
- How to Set a Custom Template for Blog Posts
- Custom template for each page
- How can I have a static title on my blog page?
- Use is_category(), is_tag(), … in functions.php
- page-slug goes to not found
- How do I add a body class to specific pages?
- How to list all titles of posts on a specific page?
- How to handle a missing page.php?
- Programatically switch page template?
- How to create a page template that retrieves content from db?
- Change path of the page’s template
- Get page id of current page from template [duplicate]
- is_page_template returning false
- remove page template from dropdown?
- Export csv and force download in template page
- WPML in custom page templates
- get_pages — parent vs child_of?
- How to pass outside function to WP_REST_Request
- Is there any way to get all the name or slug of template parts used in a page?
- page.php not displaying content
- WP-CLI not setting page template with page_template=”template-name.php”
- Create a page template with No Footer
- Register/Get sidebar?
- using the loop with a custom table
- Verify if the current page has at least one published child
- how to remove all body classes in wordpress
- Custom Post Type Archive template page not found
- Add #sidebar-2 to a custom page template
- What is wrong with my page.php?
- wp_redirect goes to infinity loop
- Single page Template for pages that begin with ‘confirmation-‘
- What content to use for inserting images
- Display one post in different formats conditionally
- Custom Page Templates
- get_avatar() as backround image
- get_the_excerpt() inside WP_Query – link URL Incorrect
- Change text size and color for tags and category meta description on product page
- Strip from the_tags() output
- How to make Dynamic Page Template based on Post ID’s
- add_rewrite_rule no longer working – possible https issue?
- Contact template doesnt appear in page template options
- Template Redirect to /2015 to use page template
- Custom page template to sidebar/widget
- How to set custom cookies in WordPress after a form is filled on a page
- Three step order form, how to go to next step
- Proper way to create custom static page
- RSS feed for a custom page template
- Add featured image as post header background image
- How to integrate custom HTML template in a premium wordpress theme?
- WordPress pass url to page template when page does not exist
- Static page won’t identify template
- page_template filter without a plugin
- How to get template link?
- Add additional templates to the templates drop down on add page menu [duplicate]
- Single page theme: Can I render other pages with their respective themes within another page?
- WordPress fetches the archive page instead of my custom template
- How to set title from page-template?
- create template for one page
- get_template_part() to render single page Theme
- How do you create a default template?
- Cannot display default template after switching to custom
- A simple form submission but notice : Trying to get property of non-object
- Custom Page Template not working when site moved from subfolder
- change the Theme dynamically
- WordPress & External Page: 404 error in IE and some others
- How can I set full width page layout in a default post page?
- Lead Generation with Cookies in WordPress
- trying to add custom landing page to Twenty Eleven- can’t get rid of Twenty Eleven header/container? [duplicate]
- Show tarifs page with menu a or b depending on menu of origin
- Page (template) with only news of the type “gallery”
- Fetching Image from other post/page with custom type
- How can I make different page templates for one category?
- Getting a custom area in a theme for dynamic content for page
- Display child page on parent
- Article Template
- Show page name in browser
- Front end user registration form [closed]
- How do I update the SEO information on dynamic pages being generated from template_include?
- Can wordpress search inside a custom page template?