Suppose we have a shortcode with two parameters, "foo" and "title". Currently, we can retrieve their values by adding arguments to the shortcode method. However, this approach has limitations. The parameters must be provided in the exact order, which can be inconvenient. Additionally, if we have a large number of parameters, it becomes cumbersome to write them all.
How can we improve? An associative array or an object to pass the shortcode parameters. This allows us to specify the parameter names along with their values, making it more flexible and easier to manage? I'm sure Laravel / you have some nice idea.
[welcome-shortcode foo="bar" title="world"]
// actually the name of the parameter does matter as they are filled by order.
public function shortcode($foo = '', $title = '')
{
return shortcode_view('welcome.shortcode', [], [])->add('section1', function () {
return 'welcome to section 1';
});
}
Suppose we have a shortcode with two parameters, "foo" and "title". Currently, we can retrieve their values by adding arguments to the
shortcode
method. However, this approach has limitations. The parameters must be provided in the exact order, which can be inconvenient. Additionally, if we have a large number of parameters, it becomes cumbersome to write them all.How can we improve? An associative array or an object to pass the shortcode parameters. This allows us to specify the parameter names along with their values, making it more flexible and easier to manage? I'm sure Laravel / you have some nice idea.
[welcome-shortcode foo="bar" title="world"]
Using the latest version of wpstarter: v1.4.15