Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn a Function in Wordpress Shortcode
    text
    copied!<p>Recently I have been playing around with Wordpress Shortcode. When following <a href="http://wp.smashingmagazine.com/2012/05/01/wordpress-shortcodes-complete-guide/" rel="nofollow">this</a> tutorial (changed a few things, of course), I found that even without returning anything (return $return_string; - part) my code is still working as intended.</p> <p>I opened PHP manual and it says:</p> <blockquote> <p>If called from within a function, the return statement immediately ends execution of the current function, and returns its argument as the value of the function call. return will also end the execution of an eval() statement or script file.</p> </blockquote> <p>My question:</p> <p>Since looks like there is nothing broken, should I keep doing what I do, or should I "return" something from my function (there is actually a downside from not "return-ing" anything I just haven't seen, yet) ? </p> <p>Edit: The code, just in case.. no "return", still processing the shortcode / loop</p> <pre><code>function looping_cat($atts, $content) { extract(shortcode_atts(array( "query" =&gt; '', "category" =&gt; '' ), $atts)); $wp_query = new WP_Query(); if(!empty($category)){ $query .= '&amp;category_name='.$category; } $wp_query-&gt;query($query); ?&gt; &lt;ul&gt; &lt;?php while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post(); ?&gt; &lt;li&gt; &lt;div&gt; &lt;?php the_post_thumbnail(); ?&gt; &lt;h2&gt;&lt;?php the_title() ?&gt;&lt;/h2&gt; &lt;/div&gt; &lt;?php the_excerpt(); ?&gt; &lt;/div&gt; &lt;/li&gt; &lt;?php endwhile; wp_reset_query(); ?&gt; &lt;/ul&gt; &lt;?php } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload