Inventory_Presser_Menu_Item_Print::maybe_insert_print_button_javascript( string $menu_item, WP_Post $item, int $depth, object $args )


Description Description

Replace a link target of "#" with JavaScript that prints the page when a menu item has a CSS class of "invp-print-button".

Top ↑

Parameters Parameters


(string) (Required) item HTML


(WP_Post) (Required) post object for the menu item


(int) (Required) depth of the item for padding


(object) (Required) nav menu arguments

Top ↑

Return Return

(string) item HTML

Top ↑

Source Source

File: includes/class-menu-item-print.php

	function maybe_insert_print_button_javascript( $menu_item, $item, $depth, $args ) {

		// does it have the magic CSS class?
		if ( ! in_array( 'invp-print-button', $item->classes ) ) {
			return $menu_item;

		// is it a custom link?
		if ( 'Custom Link' != $item->type_label ) {
			// no
			return $menu_item;

		// is the link target a #?
		if ( false !== strpos( $menu_item, 'href="#"' ) ) {
			// yes, change it to JavaScript that prints the page
			$menu_item = str_replace( 'href="#"', 'href="javascript:window.print();"', $menu_item );

		return $menu_item;