• I have to create build a block of code that will work as a template to suggest products. I would like to use a shortcode, but I don’t how to get started. I mean I know how to get started using shortcodes, but I don’t know how to approach the code I want to create. or if I’m using the right solution.
    Ideally, I want to something that would simply require a list of time that WordPress then will take to create a block of code to promote a product, something like the wirecutter.
    How can I do something like this:

    [shortcode]
    title= 
    link=
    description=
    image=
    price= 
    [/shortcode]

    Once I fill the list the shortcode would display a formatted product.
    Is shortcode the way to do this?
    Any other suggestions?
    Or what’s the best approach to get this done?
    I don’t want to use plugins.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s feasible to do so with shortcodes, but the syntax used would be critical. It’d be difficult for users to remember and accurately use the right syntax. It’d be an error prone approach. I suggest developing a custom block where the input fields are well defined and much less error prone.
    https://developer.www.ads-software.com/block-editor/tinteratedutorials/create-block/

    Thread Starter wpmhweb

    (@wppit)

    @bcworkz thanks for the suggestions, but that solution is not going to work for now, I’m still not on Gutenberg, because I don’t like it and I have plugins that still don’t support the new editor so I can’t switch.

    Moderator bcworkz

    (@bcworkz)

    Fair enough. I’m not that keen on it either. For developing shortcodes see https://developer.www.ads-software.com/plugins/shortcodes/

    I’d still be concerned about the exacting syntax. Maybe consider adding some custom fields to contain the data. Then the shortcode can pull in what it needs from the custom fields.

    Or another approach, isn’t the data you are trying to pass to the shortcode already in place as products? Couldn’t the product ID be passed and the shortcode gets the content based on the passed ID.

    If you want these suggestions within page content, shortcodes are the way to go. But product suggestions often appear below page content. In that case it may be better to modify the template itself. The template code would still need to know what products to show. This could be done via custom fields.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to create shortcode to promote products inside WordPress post’ is closed to new replies.