From the word itself, the word shortcode means exactly that: A short code; a shortcut code.
简码允许您向网站添加内容(例如小工具),而无需像开发人员通常那样添加大段代码。
例如,一段常规代码的长度大概会长成这样:
<html>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam id aliquam turpis. Vivamus quis arcu tincidunt, finibus urna eget, placerat risus. Aliquam arcu massa, finibus et lacinia sed, scelerisque nec augue. Quisque eu viverra sapien, vel consequat lorem. Integer vel erat tortor. Phasellus condimentum magna eget congue venenatis. Suspendisse blandit vehicula consectetur. Nullam sodales eleifend massa, in bibendum purus fermentum id. Morbi et turpis feugiat, malesuada ipsum sit amet, interdum nulla. In non ante nec nisl mattis gravida sit amet id lectus. </html>
在这个示例中,假设上面的代码可以让您添加一整段 Lorem Ipsum 占位符文本。
Now, a shortcode with the same exact function as the code above will look something like this, in contrast:
[lorem ipsum dolor estat]Lorem Ipsum[/lorem]
You can see how they’re miles different from each other in terms of length.
现在想象一下,这两段代码——原本冗长的代码,与仅包含单词“lorem”的简码——所做的事情完全相同:添加 Lorem Ipsum 文本。
This is what shortcodes do. They make adding widgets, functions, and a bunch of other cool stuff easier for both ordinary WordPress users and developers alike.
Where can I find shortcodes?
如果您有喜爱的插件或小工具,它们很可能都提供了可供您使用的简码。
Shortcodes Ultimate, for example, will let you choose from hundreds of shortcodes that you can use on Page Builder Sandwich (or anywhere, actually) by simply grabbing the shortcode of your choice from Shortcode Ultimate’s repository or documentation page.
Adding Custom Shortcodes on PBS
在 Page Builder Sandwich 上,您只需输入或复制粘贴到内容区域,即可直接在页面上添加简码。
我们下面使用来自 Shortcodes Ultimate 的简码进行了演示,在 Page Builder Sandwich 演示页面上添加了一个内容框:
Another thing you’ll find handy when using Page Builder Sandwich is our Shortcode Mapping feature.
根据我们之前关于简码映射(Shortcode Mapping)的一篇文章,其定义如下:
Shortcode mapping is like letting Page Builder Sandwich memorize all the shortcodes available on your site: their names, descriptions, their attributes, and what each of these attributes do.
这意味着您不再需要在各自的文档或代码库中手动查找简码。
只要您的 WordPress 网站上安装了包含该简码的插件,您就可以在 Page Builder Sandwich 上轻松使用它。
So for example, if I wanted to add a WooCommerce shortcode on my page, all I have to do is make sure that it’s installed on my WordPress site, like so:
And then, to actually add the shortcode, I’ll just go to my page, and drag and drop the Shortcode Element:
Because we already have WooCommerce installed on our WordPress site, you can see that all of the shortcodes that are available on the WooCommerce plugin are already available on Page Builder Sandwich. This is what Shortcode Mapping is.
You can also see on the upper left corner that the ACF (Advanced Custom Fields) and MailChimp shortcodes are available– because we have those instlled on our WordPress site, too.
因此,如果您想添加自定义简码,或者自己制作的简码,只要将它们安装到您的 WordPress 网站上,就可以实现。
