Replacing echo with return doesn’t work because your function is immediately terminated once it hits a return. See PHP docs for return.
It would be helpful to see your actual code, but the general concept within your shortcode function would be:
$output=""; // initialize output
while( $your_shortcode_query->have_posts() ):
$your_shortcode_query->the_post();
$foo = get_the_title();
$bar = get_permalink();
$output .= '<a href="'.$bar.'">'.$foo.'</a>'; // add to output
endwhile;
wp_reset_query();
return $output; // return output
Related Posts:
- PHP error with shortcode handler from a class
- Get page content using slug
- Where to store PHP files created by plugin / themes
- What is the correct way to build a widget using OOP
- Optimize shortcode callbacks
- How would I create a plugin for my shortcodes?
- How to prevent newline from appearing in shortcode?
- Shortcode adding p and br tags
- Enqueue script only when shortcode is used, with WP Plugin Boilerplate
- Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
- Has anyone managed to integrate the wp_editor inside a widget?
- Retrieve multiple values passed to a single attribute in a shortcode
- How do I make specific plugin functionality apply to different sites in a network?
- Shortcodes, output buffering, and WordPress functions
- Filter on the_content ignores shortcodes
- stray elements
- Pass javascript result to shortcode executer function
- Two-step login process – Is it possible?
- How to get shortcode to work inside a foreach loop called within a shortcode?
- $wp_filesystem returns NULL. What are the dependencies?
- Get returned variable from a function to add_shortcode function
- How to store accumulate multiple option values in a single array using Options_API
- What is rich_editing?
- Why is my shortcode not working
- Admin-ajax.php appending a status code to ajax response
- On plugin deactivation hide its shortcode
- My shortcode is showing up twice
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- Can’t get JS code to work with shortcode
- Is it possible to delay execution of shortcode output callback?
- Making Quote Plugin more efficient
- How do I write a shortcode that opens and closes?
- How do I alter the comment form ‘allowed tags’ text in a plugin?
- custom shortcode will not display the wrapped content
- Applying OO patterns and principles to plugin development
- Gutenberg Block showing invalid content on edit
- Append HTML Using Shortcode
- Storing product price data in the database
- What is the best way to embed an JS App in a WordPress Page?
- What is the proper way to include Bootstrap when executing a shortcode
- Secure Pages Best Practice
- Adding option to Gallery shortcode
- Failed to Open Stream: Permission Denied While Writing to an XML File in a WordPress Plugin
- Custom login doesn’t work properly
- Run Shortcode of post’s custom field in functions.php / Plugin
- Widget HTML Display Problem
- Wrap text around shortcode
- wp_nonce_field displaying twice
- Redirect to another page using contact form 7? [closed]
- How to handle shortcodes through plugin
- Using a custom shortcode from within the template of a shortcode plugin
- When echoing my own shortcode, it keeps adding a 1 at the end of my blogpost
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Automating the process of shortcode generation in a plugin – how is it done?
- Create Widget or Enable Shortcodes in Sidebar
- Getting a WordPress Debug Strategy
- Shortcode not appearing when used as post content in wp_insert_post() or possibly, shortcode not being registered at all
- WordPress shortcode returns the data before
- How to display the categories on page using shortcode?
- How to create ShortCode
- add_filter img_caption_shortcode not implemented
- shortcode tags not working in do_shortcode
- Working of foreach loop with array
- How to insert HTML/CSS/JS into my iframe plugin?
- Passing values between enclosing and enclosed shortcodes
- What is the difference between Null vs Empty (Zero Length) string?
- Setting a post’s category
- Why doesn’t update_post_meta work for certain strings?
- How to determine which capability to use?
- Font size of HTML content
- Cannot output plugin twice with shortcode
- How to call a function from a shortcode function in an oop plugin
- How to Create custom block for displaying information in content section which act like shortcode
- WPGut – Updating failed and shortcode?
- How to write a custom shortcode name book?
- Hide content for specific users with id
- Why is my shortcode not working?
- Display a custom name when the user has no name settle in his account
- How can we stop showing short code in create or edit post section
- How to return html as a string from php for WordPress
- Shortcode content is not showing. Only the [shortcode-tag] is showing
- Including content into an add_shortcode() function
- Pass javascript result to shortcode executer function
- Shortcode from a plugin not working
- foreach argument to get specific file types getting too many returns
- Shortcode Works for Logged in Users but Not Working for Guest
- Which filter to use to pre-parse form elements, which are generated by plugin’s shortcode?
- Is there a way to tell if a shorcode’s handler is being run before or after the content formatting filter?
- How to add conent (text) to Add New pages form of admin in WordPress
- Do a summary based on sections in a post
- Children Shortcodes?
- Wrapping shortcodes in another shortcode
- Cannot echo a JS variable to a jQuery plugin coming from wp_localize_script
- Multi-part form and wp_redirect()
- Create pages for authors
- Developing a wordpress.com shortcode [closed]
- WordPress simple ‘Hello World’ plugin – problems
- Shortcode rendered in preview, but empty in post
- How to display .ptm file in my WP site without JAVA
- Developing an IP lookup function using an API