Shortcode ID attribute

Have you wondered what this “Shortcode ID” value is?

If you’ve looked at the Extended block, it appeared as a read-only field. If you’re using the Shortcode Builder, it appeared as a shortcode attribute. In both cases these are self generated but the purpose of them isn’t necessarily clear.

Primary purpose for the Shortcode ID

The primary thing that CPTUI-Extended uses the value for is to provide a unique value used with the paginate_links() function that we use for blocks that have pagination available. This helps make sure that we only move to the “next page” for the contents in our layout. For example, if you had an Extended layout shown in a blog post, and clicked for the next page in the layout, this prevents WordPress from also navigating to page 2 of your blog archive.

Secondary uses for the Shortcode ID

Since we append the shortcode ID value to our wrapping markup, this also allows for unique markup attributes that could be used with your CSS and Javascript. If you need to make some tweaks to a specific layout, say it’s breaking somehow, this would allow you to affect only one instance.

You can also use it to perform conditional logic if you’re are doing any template customization. For example, if you’re using a layout for multiple content types, but only one specific instance of the layout needs custom field output, you could check for that shortcode ID being the current displayed instance and display out appropriately.

If you can think of other use cases for a unique numeral value, let us know and we can add to our list.