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
- Add self-closing shortcode button to TinyMCE in WP 4.6
- 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
- Are shortcodes case-sensitive?
- 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?
- How to make WordPress use non-greedy shortcode parsing?
- Multiple Parameters for a Shortcode
- 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
- How To Ignore a Filter On Applying Filter the Content In a Function
- Display a text message if the shortcode is not found?
- Filter on the_content ignores shortcodes
- stray elements
- Pass javascript result to shortcode executer function
- Front-End Form Submission in Shortcode
- 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
- shortcode doesn’t work
- How to store accumulate multiple option values in a single array using Options_API
- What is rich_editing?
- Why is my shortcode not working
- Loading page template into shortcode
- Admin-ajax.php appending a status code to ajax response
- Error : “Updating failed: The response is not a valid JSON response” with custom shortcode
- 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]
- How to insert HTML/CSS/JS into my iframe plugin?
- Including template in shortcodes
- Form submission to another page returning 404 error [duplicate]
- Passing values between enclosing and enclosed shortcodes
- What is the difference between Null vs Empty (Zero Length) string?
- Adding Permalink to Slides with ‘Simple Nivo Slider’ plugin?
- Setting a post’s category
- Why doesn’t update_post_meta work for certain strings?
- “Rendering of admin template [path to template] failed”
- How to determine which capability to use?
- Font size of HTML content
- Cannot output plugin twice with shortcode
- Paragraph Tags removed when contents are only a 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?
- By adding “?login – failed” code unable to access my dashboard
- Hide content for specific users with id
- How can I pass WP_Query results to a plugin?
- 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
- overwrite wordpress gallery with custom gallery shortcode
- 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
- Some data has already been output, can’t send PDF file – fpdf issue in WordPress
- How do I make two shortcode use the same id and increment it when I use them multiple times?
- 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?
- Caption Shortcode: what filter to change the image size?
- 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
- Identifying a Page Containing Shortcode at `init`
- Cannot echo a JS variable to a jQuery plugin coming from wp_localize_script
- How to show custom taxonomy child posts through shortcode in WordPress
- Multi-part form and wp_redirect()
- add short code not working
- Create pages for authors
- Loop output for custom plugin [solution found]
- Correct usage of scripts with shortcodes
- How to Pass ID through Short Code
- Shortcode attribute “title” doesn’t appear in $atts array
- Developing a wordpress.com shortcode [closed]
- using a shortcode in a hyperlink
- WordPress simple ‘Hello World’ plugin – problems
- WP Custom tables query
- Shortcode rendered in preview, but empty in post
- How to display .ptm file in my WP site without JAVA
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- Custom plugin with shortcode not working
- Developing an IP lookup function using an API
- Shortcode to return data instead of outputting HTML?
- Using a shortcode to get User Emails by role as specified in the shortcode, need help to allow for multiple roles
- Resending woo-commerce order emails from frontend