Cách thêm shortcode tùy chỉnh trên Page Builder Sandwich

Viết bởi

trong

From the word itself, the word shortcode means exactly that: A short code; a shortcut code.

Shortcode cho phép bạn thêm các thành phần vào trang web của mình (chẳng hạn như widget) mà không cần phải chèn các đoạn mã khổng lồ như các nhà phát triển thường làm.

Ví dụ: một đoạn mã thông thường, xét về độ dài, có thể trông giống như thế này:

<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>​

Đối với ví dụ này, hãy giả sử rằng đoạn mã ở trên sẽ cho phép bạn thêm toàn bộ một đoạn văn bản giữ chỗ 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.

Bây giờ hãy tưởng tượng rằng cả hai đoạn mã – Đoạn mã dài ban đầu, so với shortcode chỉ chứa từ “lorem”, đều sẽ thực hiện cùng một việc hoàn toàn giống nhau: Thêm văn bản 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?

Nếu bạn có một plugin hoặc widget yêu thích, rất có thể chúng có sẵn shortcode để bạn sử dụng.

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

Trên Page Builder Sandwich, bạn có thể thêm shortcode trực tiếp vào trang của mình chỉ bằng cách gõ hoặc sao chép-dán nó vào khu vực nội dung của bạn.

Chúng tôi đã thực hiện điều này bên dưới với một shortcode từ Shortcodes Ultimate, thêm một hộp nội dung trên trang demo Page Builder Sandwich:

Another thing you’ll find handy when using Page Builder Sandwich is our Shortcode Mapping feature.

Từ một trong những bài viết trước của chúng tôi về Shortcode Mapping, định nghĩa như sau:

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.

Một phần điều này có nghĩa là bạn không còn phải tìm kiếm shortcode theo cách thủ công trên các tài liệu hướng dẫn hoặc kho lưu trữ tương ứng của chúng nữa.

Miễn là bạn đã cài đặt plugin có chứa shortcode đó vào trang web WordPress của mình, nó sẽ dễ dàng có sẵn để bạn sử dụng trên 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.

Vì vậy, nếu bạn muốn thêm các shortcode tùy chỉnh hoặc các shortcode do chính bạn tạo ra, bạn hoàn toàn có thể làm được, miễn là bạn đã cài đặt chúng vào trang web WordPress của mình.

Here are some other helpful plugins that you can use to create your own custom shortcodes: