Site logo

Archived topic

Several shortcodes in one snippet/function

5 replies · Started by Igor on August 22, 2021

Viewing posts 1–6 of 6

Hi there,

I would like to add several shortcodes in one snippet, and I could not sort it out with googling.
I will just add 5 more websites/links in the same way as BBC below.

Is there a better way than just copy pasting the code 5x?

add_shortcode( 'BBC', function() {
    ob_start();
    // Start your PHP below
	
	echo 'BBC Good Food, <a href="https://www.bbcgoodfood.com">website</a>';
  
    // End your PHP above
    return ob_get_clean();
} );

Hi there,

for a simple shortcode like that, i would go with 5x copies of it. Lot easier to read and maintain and keeps your [shortcode] nice and simple.

Thanks David, just a final question:

is it a better practice to have all the shortcodes of this type in the same snippet or create separate snippet for each?

Theres not really a best practice. I would put them all in the one snippet, just so i only have one to edit if i want to update them all :)

Thanks :)

You're welcome

This archived topic is closed to new replies.