Last Modified: KB » WooCommerce KB Articles Pro
[kb /] Shortcode

The [kb /] Shortcode produces a summary of KB Articles in a variety of ways. By default, it also displays a KB Article search box, Categories, and Tags. However, all of this behavior can be altered through the Shortcode Attributes described in this article.

Default Behavior

This example is quick & easy. The built-in defaults are all in effect because there are no additional Shortcode Attributes supplied in this example. By default, the [kb /] Shortcode will display Articles for the current Product (if it's displayed on a Product page), otherwise it will display a list of all KB Articles, regardless of Product.

[kb /]

Note: While this Shortcode is extremely useful, it is not designed to be an official archive view for KB Articles. It has been designed as a way to showcase a summary of KB Articles in list format. For that reason, it doesn't support pagination, author-based archives, sidebar widgets, or other advanced features found in the official Post Type archive view for KBAs. For those advanced features please see: WP Theme Integration.

Optional Shortcode Attributes

for_product_ids="{int,int}"

This attribute has a dynamic default value. If the [kb /] Shortcode is displayed from a Product page (e.g., in the Knowledge Base Product Tab), then it defaults to the current Product ID. If it's displayed anywhere else it defaults to being empty, which means that it will display KB Articles regardless of Product.

e.g., Show KB Articles for a specific WooCommerce Product by ID. In this case Product ID 123.

[kb for_product_ids="123" /]

Show KB Articles for three different Products, comma-delimited in this example.

[kb for_product_ids="123,456,789" /]


article_ids="{int,int}"

This attribute can be used to filter the list down to a specific set of KB Articles by their ID.

e.g., Only show one specific KB Article in the list.

[kb article_ids="123" /]

Only show these three KB Articles in the list.

[kb article_ids="123,456,789" /]

Note: When you specify this attribute it also dictates the sort order of the KB Articles that are returned, no matter what you set order_by="" to. In short, KB Article IDs that you comma-delimit in this list, will always be displayed in the exact order in which they are listed. No exceptions.


in_category_ids="{int,int}"

Used to limit the list to KB Articles that are in specific Categories.

e.g., Only show KB Articles in Category ID 123.

[kb in_category_ids="123" /]

Only show KB Articles in one of these three Category IDs.

[kb in_category_ids="123,456,789" /]


with_tag_ids="{int,int}"

Used to limit the list to KB Articles that have specific Tags.

e.g., Only show KB Articles that have Tag ID 123.

[kb with_tag_ids="123" /]

Only show KB Articles with one of these three Tag IDs.

[kb with_tag_ids="123,456,789" /]


tax_query_logic="{AND|OR}"

This attribute defaults to a value of OR. It controls the logic in a scenario where you have both the in_category_ids="" attribute and also the with_tag_ids="" attribute as well. So by default, if you specify both of these, the list will display any that match, instead of using AND logic, which would require that KB Articles be in one of the Categories and also have one of the Tags too.

For example, here I am listing KB Articles in Category 123, OR those that have the Tag ID 456. This is the default behavior, because tax_query_logic="" defaults to a value of OR. I don't need to define tax_query_logic="" at all. I'm relying on the default behavior.

[kb in_category_ids="123" with_tag_ids="456" /]

List KB Articles in Category 123, AND they must also have the Tag ID 456.

[kb in_category_ids="123" with_tag_ids="456" tax_query_logic="AND" /]


order_by="{field:DIR,field:DIR}"

This attribute defaults to a value of comment_count:DESC,modified:DESC. As you'd expect, this controls the sort order of KB Articles in the list. The value of this attribute consists of a list of field names in comma-delimited format, but also in colon-delimited format, which allows one of ASC or DESC to be given as a direction.

Note: The order_by="" attribute has no effect when you also set the article_ids="" attribute. Please see the details for the article_ids="" attribute to learn more about why that is the case.

Valid order_by="" field names include:

  • ID (by KB Article ID)
  • author (by KB Article Author)
  • title (by KB Article Title)
  • name (by KB Article Slug)
  • date (by Publication Date)
  • modified (by Last Modified Date & Time)
  • rand (in random order; use DESC or ASC, does not matter)
  • comment_count (by comment count; i.e., popularity)

The default behavior is to first order by popularity (comment_count:DESC),
and then again by the last modified time in DESC order (modified:DESC).

[kb order_by="comment_count:DESC,modified:DESC" /]

Show only the top 10 most popular KB Articles (based on comment count).

[kb order_by="comment_count:DESC" max="10" /]

Show the 10 most recently updated KB Articles (based on last modified time).

[kb order_by="modified:DESC" max="10" /]


max="{int|-1}"

This attribute controls the maximum number of KB Articles that should be displayed in the list. It defaults to a value of 25. Using the special value of -1 indicates there is no limit; i.e., show all KB Articles matching other criteria supplied by all Shortcode Attributes collectively.

e.g., Show only the top 10 most popular KB Articles (based on comment count).

[kb order_by="comment_count:DESC" max="10" /]

Show the 10 most recently updated KB Articles (based on last modified time).

[kb order_by="modified:DESC" max="10" /]

Show all KB Articles in alphabetical order (by title).

[kb order_by="title:ASC" max="-1" /]


one_line_titles="{bool}"

This attribute defaults to a value of true, which forces text clipping to occur for each title in the list of KB Articles; i.e., it forces each KB Article title to be at most one line. If the title is too long for a single line, the title is clipped automatically via CSS and an ellipsis is used to indicate there is more... Hovering over the title with your mouse will always reveal the full title in the form of a browser tooltip.

e.g., To alter the default behavior and show the full title, even if it spans multiple lines in the list.

[kb one_line_titles="false" /]


show_excerpts="{bool}"

Do you want to show content excerpts in the list? This defaults to a value of false (do not show excerpts). You can set this to true if you do want to display excerpts of the underlying KB Article content in the list.

[kb show_excerpts="true" /]


show_search_box="{bool|top|bottom}"

Do you want to show a search box? This defaults to a value of true (show the search box at the top). You can set this to false to hide the search box. Or, you can set this explicitly to one of top or bottom to show the search box in a specific location; i.e., at the top or bottom of the list.

e.g., Do not show the search box.

[kb show_search_box="false" /]

Show the search box, but show it at the bottom of the list.

[kb show_search_box="bottom" /]


search_link_target="{_self|_blank}"

If show_search_box="true", this defaults to a value of _self. It controls the underlying search <form target="" attribute, which means that you can set search_link_target="_blank" if you want searches to be opened in a new window instead of in the same _self window by default.

[kb search_link_target="_blank" /]

See also: tax_link_target="_blank"
See also: link_target="_blank"


show_categories="{bool}"

This defaults to a value of true (show Categories). By default, a list of 25 top-level Categories is shown on the right-hand side of the list. Set this to false if you don't want to show the Categories, which leaves more room in the list for longer KB Article titles; assuming you also set show_tags="false".

[kb show_categories="false" /]


child_categories_of="{int|-1}"

If show_categories="true", this attribute defaults to child_categories_of="0" (show top-level Categories only; i.e., having a parent Category ID of 0). In other words, this attribute controls the Category depth that you want to display, and/or the parent Category ID that should be used as the basis for Categories that appear in the list. You can also set this to -1 to effectively disable all Category list filters, thereby showing Categories regardless of depth.

e.g., Show only top-level Categories. This is the default behavior when show_categories="true".

[kb show_categories="true" child_categories_of="0" /]

Show all Categories, regardless of depth.

[kb show_categories="true" child_categories_of="-1" max_categories="0" /]

Show all Categories that have Category ID 3 as their parent Category.

[kb show_categories="true" child_categories_of="3" max_categories="0" /]


max_categories="{int|0}"

If show_categories="true", this attribute controls the maximum number of Categories that should be displayed in the list. It defaults to a value of 25. Using the special value of 0 indicates there is no limit; i.e., show all Categories matching other criteria, such as child_categories_of="".

e.g., Show only 10 top-level Categories.

[kb show_categories="true" child_categories_of="0" max_categories="10" /]


show_tags="{bool}"

This defaults to a value of true (show Tags). By default, a list of 25 applicable Tags is shown on the right-hand side of the list. Set this to false if you don't want to show the Tags, which leaves more room in the list for longer KB Article titles; assuming you also set show_categories="false".

[kb show_tags="false" /]


max_tags="{int|0}"

If show_tags="true", this attribute controls the maximum number of Tags that should be displayed in the list. It defaults to a value of 25. Using the special value of 0 indicates there is no limit; i.e., show all applicable Tags.

e.g., Show only 10 Tags.

[kb show_tags="true" max_tags="10" /]


tax_link_target="{_self|_blank}"

If show_categories="true" or show_tags="true", this attribute controls the <a target="" attribute for Category/Tag links in the list. This attribute defaults to a value of _self (same window). Set this to _blank if you want Category/Tag links to open in a new window.

[kb tax_link_target="_blank" /]

See also: search_link_target="_blank"
See also: link_target="_blank"


link_target="{_self|_blank}"

This attribute controls the <a target="" attribute for KB Article links in the list (i.e., the clickable title). This attribute defaults to a value of _self (same window). Set this to _blank if you want KB Article links to open in a new window.

[kb link_target="_blank" /]

See also: search_link_target="_blank"
See also: tax_link_target="_blank"