The What
Syntax
string beans_add_attributes( string $id, string|array $attributes [, mixed $... ]] );
Description
This function provides the ability to customize attributes before they are escaped and returned for processing. It provides a filter $id . '_attributes'
, allowing code (including third code) to customize one or more of the attributes.
This function does the following:
- Grabs all of the arguments that were passed to it.
- Calls
beans_apply_filters
using the filter event name$id . '_attributes'
to invoke each of the registered callbacks. - Calls
beans_esc_attributes()
which does the following:- Escapes each attribute by passing it through
esc_attr()
- Flattens the array into a string in the following format: attribute_key = attribute_value
- Escapes each attribute by passing it through
- Returns the string of attributes.
The power of Beans is the ability to customize whatever you need via the unique ID and internal functionality. Using the specified $id
, a child theme or plugin can register to various events in order to customize. You can:
- Remove an attribute.
- Add a new attribute.
- Change an attribute, such as the
class
attribute. - Remove an attribute.
It provides you with the means to customize the default behavior within Beans or your custom child theme or plugin.
Parameters
id
- The unique ID associated with the query string or HTML tag that require these attributes. This ID can contain sub-hooks.
attributes
- The attributes specified as a key/value pair. The “key” is the attribute name and value is the attribute’s value.
...
- optional Additional argument(s) to be passed to the registered callbacks.
Return Values
Returns the filtered and escaped attributes.
Available Event Hooks
This function generates the following event hooks, which are available for for third party code to register and customize the HTML:
- Attribute filter
$id . '_attributes'
– to add, change, or remove one or more attributes.
Your functions are bloated. Put them on a diet. Think "skinny" and "as few lines as possible."
Show It in Action
More coming soon…keep checking back.
Go DeepPro
In this section, you will go deeper into the instruction.