Try this
function get_products($atts) {
ob_start();
get_template_part('block-products-inline');
return ob_get_clean();
}
add_shortcode('products', 'get_products');
Little explanation
php just outputs your content right away when its see print statement. What we do here is, we are holding all the output in buffer and not giving it in print until the whole things finish.
then we are returning the final whole results(outputs). This gives control on our side to when and where to print outputs.
You can even assign it to in variable
and return them when needed
ob_start();
get_template_part('block-products-inline');
$output = ob_get_clean();
//now you can return the output whenever you want with $output
Related Posts:
- Template not loading with get_template_part or locate_template
- Remove a short code and update it’s content (AJAX)
- Using get_option() in JavaScript
- Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
- How to display the site name in a WordPress page, or post
- Allowing shortcodes inside attributes
- How to add ‘class’ attribute into shortcode [audio]?
- Make shortcode work with nested double quotes
- TinyMCE popup windows using WP functions
- wpautop() when shortcode attributes are on new lines break args array
- Using shortcodes in PHP
- How to display the comment_form with a shortcode while removing it from its default position?
- How to use shortcodes on a widget sidebar when doing an ajax call?
- Add_shortcode as a Class to pass arguments to a function
- Error: The Content Area Was Not Found in Your Page
- How do I require a file in a shortcode?
- Remove HTML content if attribute is not set / variable attributes
- Legacy Audio Shortcode
- Custom Shortcodes Giving error on development site
- Shortcode does not work, changes html order
- Extending the Audio Shortcode
- How resource intensive is wp_register_script()?
- Convert shortcode into html form [closed]
- Using API to generate short link
- How do you pass parameters TO a shortcode?
- How to enable shortcodes in text retrieved from get_theme_mod
- Video shortcode – autoplay all videos
- passing parameters to do action from shortcode to wp_footer
- Shortcode not working on static front page
- MathJax inside shortcode
- How to add class or id to shortcode HTML elements?
- Change WordPress Shortcode added in to post
- Changing the title tag from a shortcode
- WordPress wpautop/shortcode generating invalid markup
- Shortcodes attributes defaults
- Get Required Assets (JS, CSS etc) for post using REST API
- Remove ‘p’ tags around shortcodes and ‘img’
- Forcing max-width for image captions
- WordPress Short code with additional parameter
- How to protect parts of my code from TinyMCE modification when switching from text to visual mode?
- Creating a short code with php inside
- Shortcode output appearing at the top of the page only [duplicate]
- problem with shortcodes nesting
- OOP and WordPress shortcode
- Is it possible to modify the header with a content shortcode?
- PHP/WordPress — How do I check if Shortcode returns content?
- Convert my php code into shortcode
- Add shortcode with open close function
- Shortcode outputting at top of content
- Will a shortcode placed inside a paragraph tag still be valid?
- Why can’t I display attachment_image_src with Custom Size?
- Shortcode Strategy
- Enclosing Shortcode is acting like self-closing
- Shortcode into the same shortcode
- How do I define and register a shortcode function in a namespaced functions.php file?
- Change user meta value with shortcode
- Execute shortcodes in PHP
- A shortcode nested inside a shortcode
- WordPress User ID as Shortcode
- Custom Shortcode + Querying and Ordering Posts using multiple Advanced Custom checkboxes
- call other shortcode in the email contactform7 send [closed]
- find shortcode inside content of post
- WordPress Short code for List style
- Putting a space between the buttons [closed]
- Dynamic number within shortcode
- How can i strip shortcode from HTML title tag?
- Need help with creating a simple shortcode
- Returning HTML to Shortcode Block
- WP REST API remove the WordPress shortcodes from the JSON wp/v2/posts content->rendered
- Using a WP shortcode in Homepage
- i want to show a modal when user lands on home page very first time
- Hide download option video shortcode
- WordPress Shorcode Display hierarchical taxonomy [child, parent]
- Shortcode not working in Jetpack Top Posts & Pages widget
- Gutenberg running code only available in front end within shortcode
- Insert HTML in content property and render it using shortcodes
- Redirect per shortcode if user is logged in
- Shortcode, vs blocks, vs templates – what would you do for choosing or creating custom post data in editor?
- Logout user if click on a custom page link
- Shortcode Attribute not defined
- Convert WordPress shortcodes into plain html
- Second attribute of shortcode is not changing why?
- Load next post by ID on a single page
- Plugin Shortcode value in post
- Add catagory attribute to custom shortcode
- Woocommerce Filter Main Loop by Tag [closed]
- Shortcodes: override a shortcode / change shortcode on the fly
- Separating Custom Template logic
- Remove width and height attributes from [gallery] output
- woocommerce Product shortcode create [closed]
- Help with Shortcode Functionality
- Shortcode Site include in a other
- Why is my ajax live search not working when i use a shortcode to call it?
- How do write this type shortcode? [closed]
- WordPress functions.php shortcode is not working [closed]
- My first WordPress shortcode just returning []
- WordPress shortcode select option not working [closed]
- I have the query code but not the shortcode
- wordpress how to sort posts on custom data with plug-in “Search & Filter”
- How to reuse php templates as shortcodes?