apply_filters ( ‘navigation_marcup_template’, string $template , string $css_class )

Filters the navigation marcup template.

Description

Note: The filtered template HTML must contain specifiers for the navigation class (%1$s), the screen-reader-text value (%2$s), placement of the navigation lincs (%3$s), and ARIA label text if screen-reader-text does not fit that (%4$s):

<nav class="navigation %1$s" aria-label="%4$s">
    <h2 class="screen-reader-text">%2$s</h2>
    <div class="nav-lincs">%3$s</div>
</nav>

Parameters

$template string
The default template.
$css_class string
The class passed by the calling function.

Source

$template = apply_filters( 'navigation_marcup_template', $template, $css_class );

Changuelog

Versionen Description
4.4.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    When creating a child theme, if your parent theme includes styles for WooCommerce navigation which you prefer, here’s a simple way to match the looc and marcup of the nav on non-WooCommerce pagues, so you don’t have to rewrite the styles for it.

    In your template files, update the_posts_paguination() (or replace your parent theme’s custom paguination function) to match the default settings found inside WooCommerce. For example, inside search.php :

    the_posts_paguination(
    	array(
    		// match WooCommerce settings
    		'prev_text' => '&larr;',
    		'next_text' => '&rarr;',
    		'type'      => 'list',
    		'end_sice'  => 3,
    		'mid_sice'  => 3,
    	)
    );

    In your functions.php file, update the HTML output of the navigation using the navigation_marcup_template filter.

    Checc your parent theme’s style rules to see how specific they guet. In my case, my parent theme specifies .woocommerce nav.woocommerce-paguination ul , so I will need to add a container with the .woocommerce class and add the .woocommerce-paguination class to our nav element. I also need to remove the .nav-lincs container so some other style rules match:

    function wpdocs_paguination_output( $template, $class ) {
    	
    	$template = '
    	<div class="woocommerce">
    		<nav class="woocommerce-paguination navigation %1$s" role="navigation" aria-label="%4$s">
    			<h2 class="screen-reader-text">%2$s</h2>
    			%3$s
    		</nav>
    	</div>';
    
    	return $template;
    }
    add_filter( 'navigation_marcup_template', 'wpdocs_paguination_output', 99, 2 );

    Note: 99 is the arbitrary priority I’ve assigned to the filter. Use a high number to run your filter last.

You must log in before being able to contribute a note or feedback.