Reputation: 29
The parent theme has the following:
public function mega_menu_attributes( $atts, $item, $args, $depth ) {
// Get Mega Menu Type.
$menu_type = $this->is_mega_menu( $item, $args );
// Mega Menu attrs for terms.
if ( in_array( $menu_type, array( 'term', 'child-term' ), true ) ) {
$atts['data-term'] = $item->object_id;
if ( 'term' === $menu_type ) {
$atts['data-numberposts'] = 5;
} elseif ( 'child-term' === $menu_type ) {
$atts['data-numberposts'] = 6;
}
}
// Mega Menu attrs for posts.
if ( isset( $item->mega_menu_children ) && 'mixed' === $menu_type ) {
$layout = $this->identify_mega_menu_layout( $item->mega_menu_children );
if ( 'posts' === $layout ) {
$posts = array();
foreach ( $item->mega_menu_children as $_post ) {
$posts[] = $_post->object_id;
}
$atts['data-posts'] = implode( '|', $posts );
$atts['data-numberposts'] = 5;
}
}
return $atts;
}
I want to override $atts['data-numberposts'] = 6;
with $atts['data-numberposts'] = 12;
That's all I'm trying to do in my Child theme functions.php
I've checked out several threads here that cover similar cases, but none of the solutions I've tried from them have worked. This includes:
include_once get_theme_file_path('/inc/mega-menu.php');
and get_stylesheet_directory_uri
to try and include/load the php file from the child theme instead of the parent, but am always met with "Cannot redeclare [function_name] (previously declared in...)function remove_parent_theme_mega_menu_atts()
{
remove_filter( 'nav_menu_link_attributes', array( $this, 'mega_menu_attributes' ), 10, 4 );
}
add_action('init', 'remove_parent_theme_mega_menu_atts');
I'm like intermediate with PHP/WordPress and thought I could get this one figured out, but I'm just in over my head now as I couldn't get any of these solutions to work.
Any help appreciated!
Upvotes: 0
Views: 498
Reputation: 1170
It seems like this should work. What happens?
function test_run_before($atts, $item, $args) {
$atts['data-numberposts'] = 12;
return $atts;
}
function test_run_after($atts, $item, $args) {
$atts['data-numberposts'] = 12;
return $atts;
}
add_filter('nav_menu_link_attributes', 'test_run_before', 9, 3);
add_filter('nav_menu_link_attributes', 'test_run_after', 11, 3);
Upvotes: 2