I have a php function which loops through a custom post type and outputs a number of different elements.

For example:

  1. an opening li tag
  2. an img tag
  3. an opening div tag
  4. a title
  5. a description
  6. a button
  7. a closing div tag
  8. a closing li tag

I have attached the function to a shortcode [sc_loop]. The user enters the shortcode on a page and the loop in my function gets executed and outputs the elements without any problems.

However, I want the user to be able to format elements 4,5 and 6 individually (for example font size, color, bold, underline etc.) using the tinyMCE rich text editor.

My first thought was to assign each element it's own shortcode ([sc_title], [sc_description], [sc_button]), each outputting the relevant information from my CPT loop.

But how do I get the individual shortcodes to fire within my [sc_loop] shortcode whilst still enabling the user to format each shortcode individually?

Thanks in advance for any help!

  • you definitely want parameters, but without your code, it's hard to help implement – rudtek Dec 20 '16 at 17:25

Probably you need to create a shortcode with parameters. You should have different parameters for font size, color, bold, underline or anything else. The user should insert a value for each of these parameters in the shortcode.

You can find what you need here https://developer.wordpress.org/plugins/shortcodes/shortcodes-with-parameters/

It is a little tricky though because you must check the user input, because you can never be sure the user will input the proper value of a parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.