WP_HTML_Processor::get_current_depth
Returns the nesting depth of the current location in the document.
Example:
$processor = WP_HTML_Processor::create_fragment( '<div><p></p></div>' ); // The processor starts in the BODY context, meaning it has depth from the start: HTML > BODY. 2 === $processor->get_current_depth();
// Opening the DIV element increases the depth. $processor->next_token(); 3 === $processor->get_current_depth();
// Opening the P element increases the depth. $processor->next_token(); 4 === $processor->get_current_depth();
// The P element is closed during `next_token()` so the depth is decreased to reflect that. $processor->next_token(); 3 === $processor->get_current_depth();
Method of the class: WP_HTML_Processor{}
No Hooks.
Returns
Int. Nesting-depth of current location in the document.
Usage
$WP_HTML_Processor = new WP_HTML_Processor(); $WP_HTML_Processor->get_current_depth(): int;
Changelog
| Since 6.6.0 | Introduced. |
WP_HTML_Processor::get_current_depth() WP HTML Processor::get current depth code WP 6.9
public function get_current_depth(): int {
return count( $this->breadcrumbs );
}