Support » Plugin: Advanced Sidebar Menu » How can a child menu be expanded by default?

  • Resolved webuser1

    (@webuser1)


    Greetings experts,

    We purchased the Advanced Sidebar Pages Menu and for the most part, works great.

    The issue we currently have is we would like to have some grandchild menu expand by default.

    Currently, only child menu expands by default.

    Any ideas how to make some grandchild menus expand by default?

    Here is an example:

    Child Menu – (the – represents expanded child menu
    first grandchild +
    second grandchild –
    items
    items
    Here, we had to click grand child menu to change from + to – to expand and show some items

    We would like the ability to configure the grandchild to stay expanded (-) by default.

    Does this plugin have the ability to do this?

    Our searches have not turned any solution yet.

    Thanks in advance.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Mat Lipe

    (@mat-lipe)

    Hi webuser,

    I you add this JS to your site the grandchild menus will open when the page loads.

    (function ($) {
    	$( function() {
    		setTimeout(function () {
    			$('.child-sidebar-menu .has_children.closed span').click();
    		}, 500);
    	});
    })(jQuery);

    Have a great day!

    Mat Lipe

    Hi Mat,

    Thanks for the great solution.

    There is one problem though.

    We do not want ALL grandchildren to be open by default; just some selected grandchild of certain children.

    If there is any way to stick that solution to certain widgets but not all, that would be greatly appreciated.

    Many thanks for your help.
    –W–

    Plugin Author Mat Lipe

    (@mat-lipe)

    Hi W,

    Certainly, the code could be adjusted to target a specific page or widget by adding the selector like so:

    (function ($) {
    	$( function() {
    		setTimeout(function () {
    			$('<selector goes here> .child-sidebar-menu .has_children.closed span').click();
    		}, 500);
    	});
    })(jQuery);

    If you wanted to target a specific widget you would change <selector goes here> to the id of the widget e.g. #advanced_sidebar_menu-2.
    If you wanted to target a specific page you would change <selector goes here> to the class of the page e.g. .page-id-2.

    If you need help finding the id or class you may send me links and I will let you know what they are.

    Have a great day!

    Mat Lipe

    I found it.

    Thanks so much for your kindness.

    My only concern, if you would be kind enough to assist one more time is determining what js file to stick the code in.

    I am Vanguard theme, unfortunately, it is internal:

    http://preview.themeforest.net/item/vanguard-business-portfolio-wordpress-theme/full_screen_preview/3562193?_ga=2.239238275.1473499094.1537822152-1136655187.1532637022

    There are several js files.

    Not sure how familiar you with this theme to make the recommendation of which file to put my script into; does it really matter?

    I like themes that give you the option to write custom JS just as you have the option to write custom CSS.

    I didn’t purchase this theme.

    Many thanks for your help.

    Or perhaps, it belongs in a plugin file since I am using Advanced Sidebar pages menu plugin?

    Plugin Author Mat Lipe

    (@mat-lipe)

    Hi W,

    You could use a simple plugin for adding custom JS to your site. Here a are a couple of high rated ones

    1. https://wordpress.org/plugins/custom-css-js/
    2. https://wordpress.org/plugins/custom-css-and-javascript/

    If you prefer to have a JS file you could register a new one and add it to your theme.

    Otherwise, I recommend not adding it to any files in the plugin because the change will be lost when you update.

    Have a great night!

    Mat Lipe

    Hi Mat,

    I could not use any of the JS links you provided. It doesn’t allow to add new script.

    I suspect this is because those features are in the premium version.

    So, I decided to go the route of creating a new file with your script and register them.

    Below is what I have so far. I have commented them for clarity.

    What I would need clarification on are explained below.

    function wptuts_scripts_with_jquery()
    {
    // Register the script for a plugin:
    wp_register_script( ‘custom-script’, plugins_url( ‘/js/custom-script.js’, __FILE__ ), array( ‘jquery’ ) );
    // or
    // I can register the script it for a theme:
    wp_register_script( ‘custom-script’, get_template_directory_uri() . ‘/js/custom-script.js’, array( ‘jquery’ ) );

    // Enqueue the script:
    wp_enqueue_script( ‘custom-script’ );
    }
    add_action( ‘wp_enqueue_scripts’, ‘wptuts_scripts_with_jquery’ );

    //Here is your script that I created a file for called custom-script.js:
    (function ($) {
    $( function() {
    setTimeout(function () {
    $(‘page-id-3646.child.has_children.closed span’).click();
    }, 500);
    });
    })(jQuery);

    I need two clarifications;
    One, put it in plugin folder or theme folder?
    Two, Am I using the correct child name based on the widget script below?

    $sidebar = $widget.parent();

    if ( $sidebar.parent().hasClass(‘closed’) ) {
    $sidebar.parent()
    .removeClass( ‘closed’ )
    .find( ‘.handlediv’ ).attr( ‘aria-expanded’, ‘true’ );

    $children = $sidebar.children(‘.widget’);

    // Make sure the dropped widget is at the top
    if ( $children.length > 1 ) {
    child = $children.get(0);
    item = $widget.get(0);

    if ( child.id && item.id && child.id !== item.id ) {
    $( child ).before( $widget );
    }
    }
    }

    The widget file is very long and I thought I post the relevant part to show whether I am using it correctly in your script.

    Many thanks Mat for your patience.

    Plugin Author Mat Lipe

    (@mat-lipe)

    Hi W,

    I recommend you put the file in your theme.

    I’m not sure what you are asking here

    Two, Am I using the correct child name based on the widget script below?

    The JS I provided will work on any of the widgets.

    Have a great day!

    Mat Lipe

    Thank you very much for all your help Mat.

    Hi Mat,

    Please forgive me for one more question, please.

    I tried to implement this per your instructions but it is still not working. I would appreciate you looking over my approach and tell me if I missed a step or so.

    First, here is the script you wrote that I am using:

    (function ($) {
        $( function() {
            setTimeout(function () {
                $('page-id-2110 .child-sidebar-menu .has_children.closed span').click();
                   }, 500);
        });
    })(jQuery);

    I created a file for this called custom-script and uploaded the file into the theme’s js folder like theme/js/custom-script.js

    Then I registered the script with the following:

    function wptuts_scripts_with_jquery()
    {
        // I can register the script it for a theme:
        wp_register_script( 'custom-script', get_template_directory_uri() . '/js/custom-script.js', array( 'jquery' ) );
    
        // Enqueue the script:
        wp_enqueue_script( 'custom-script' );
    }
    add_action( 'wp_enqueue_scripts', 'wptuts_scripts_with_jquery' );

    I added this script to functions.php. This functions.pp is inside wp_includes folder.

    What am I missing?

    I did not add it into functions.php in the theme’s folder.

    Many thanks for all your help.

    Plugin Author Mat Lipe

    (@mat-lipe)

    Hi W,

    The code should go into your theme’s functions.php file instead of any file within wp_includes.

    Also, if you are using a child theme you will need to change this line

    wp_register_script( ‘custom-script’, get_template_directory_uri() . ‘/js/custom-script.js’, array( ‘jquery’ ) );

    To

    wp_register_script( ‘custom-script’, get_stylesheet_directory_uri() . ‘/js/custom-script.js’, array( ‘jquery’ ) );

    Good Luck

    Mat Lipe

    Hi Mat,

    I didn’t put it into my theme’s functions.php file because it is all php.

    Not sure how to integrate that.

    Here is the theme’s functions.php.

    Sorry for the bother and very grateful for your patience and continued assistance.

    <?php
    /**
     * unisphere framework functions
     */
    
    /**
     * Define framework contants
     */
    remove_filter('template_redirect', 'redirect_canonical'); 
    
    define( 'UNISPHERE_THEMENAME', 'Vanguard' ); // The theme name
    define( 'UNISPHERE_THEMESHORTNAME', 'vanguard' ); // The theme short name
    define( 'UNISPHERE_THEMEOPTIONS', 'vanguard' ); // The theme database option variable
    define( 'UNISPHERE_NOTIFIER_FILE', 'http://notifier.unispheredesign.com/vanguard/notifier.xml' ); // The notifier file containing the latest version of the theme
    define( 'UNISPHERE_GOOGLE_WEB_FONTS_FILE', 'http://notifier.unispheredesign.com/vanguard/update-font-list.php' ); // The remote file containing the latest Google web fonts
    
    // Folder shortcuts
    define( 'UNISPHERE_PLUGINS', get_template_directory() . '/plugins' ); // Shortcut to point to the /plugins/ dir
    define( 'UNISPHERE_LIBRARY', get_template_directory() . '/library' ); // Shortcut to point to the /library/ dir
    define( 'UNISPHERE_ADMIN', UNISPHERE_LIBRARY . '/admin' ); // Shortcut to point to the /admin/ dir
    define( 'UNISPHERE_FONTS', trailingslashit(ABSPATH) . 'wp-content/uploads/fonts' );
    define( 'OPTIONS_FRAMEWORK_URL', UNISPHERE_LIBRARY . '/admin/');
    
    // URI shortcuts
    define( 'UNISPHERE_CSS', get_template_directory_uri() . '/css', true ); // Shortcut to point to the /css/ URI
    define( 'UNISPHERE_IMAGES', get_template_directory_uri() . '/images', true ); // Shortcut to point to the /images/ URI
    define( 'UNISPHERE_JS', get_template_directory_uri() . '/js', true ); // Shortcut to point to the /js/ URI
    define( 'UNISPHERE_FONTS_URL', trailingslashit(site_url()) . 'wp-content/uploads/fonts');
    define( 'UNISPHERE_ADMIN_CSS', get_template_directory_uri() . '/library/admin/css', true ); // Shortcut to point to the /library/admin/css/ URI
    define( 'UNISPHERE_ADMIN_IMAGES', get_template_directory_uri() . '/library/admin/images', true ); // Shortcut to point to the /library/admin/images/ URI
    define( 'UNISPHERE_ADMIN_JS', get_template_directory_uri() . '/library/admin/js', true ); // Shortcut to point to the /library/admin/js/ URI
    define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/library/admin/');
    
    /**
     * Include required framework files
     */
    require_once(UNISPHERE_LIBRARY . '/plugins.php');
    require_once(UNISPHERE_LIBRARY . '/layerslider.php');
    require_once(UNISPHERE_LIBRARY . '/options.php');
    require_once(UNISPHERE_LIBRARY . '/helpers.php');
    require_once(UNISPHERE_LIBRARY . '/misc.php');
    require_once(UNISPHERE_LIBRARY . '/wp-head.php');
    require_once(UNISPHERE_LIBRARY . '/breadcrumbs.php');
    require_once(UNISPHERE_LIBRARY . '/post-types.php');
    require_once(UNISPHERE_LIBRARY . '/semantic-classes.php');
    require_once(UNISPHERE_LIBRARY . '/fonts.php');
    require_once(UNISPHERE_LIBRARY . '/scripts.php');
    require_once(UNISPHERE_LIBRARY . '/menus.php');
    require_once(UNISPHERE_LIBRARY . '/media.php');
    require_once(UNISPHERE_LIBRARY . '/widgets.php');
    require_once(UNISPHERE_LIBRARY . '/gallery.php');
    require_once(UNISPHERE_LIBRARY . '/custom-fields.php');
    require_once(UNISPHERE_LIBRARY . '/shortcodes.php');
    require_once(UNISPHERE_LIBRARY . '/comments.php');
    require_once(UNISPHERE_LIBRARY . '/update-notifier.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/popular-posts.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/recent-posts.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/popular-portfolio.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/recent-portfolio.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/twitter.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/contact-form.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/flickr.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/sub-pages.php');
    require_once(UNISPHERE_LIBRARY . '/widgets/social.php');
    require_once(OPTIONS_FRAMEWORK_URL . 'options-framework.php');
    require_once(UNISPHERE_LIBRARY . '/one-click-demo-import.php');
    
    /**
     * Add default theme options to database on theme activation
     */
     
    if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
    	
    	require_once OPTIONS_FRAMEWORK_URL . 'options-interface.php';
    
    	// Loads the options array from the theme
    	require_once OPTIONS_FRAMEWORK_URL . 'options.php';
    	
    	// Updates the unique option id in the database if it has changed
    	optionsframework_option_name();
    
    	$optionsframework_settings = get_option('optionsframework');
    	
    	// Gets the unique id, returning a default if it isn't defined
    	if ( isset($optionsframework_settings['id']) ) {
    		$option_name = $optionsframework_settings['id'];
    	}
    	else {
    		$option_name = 'optionsframework';
    	}
    
    	// If the option has no saved data, load the defaults
    	if ( !get_option($option_name) ) {
    		
    		if ( isset($optionsframework_settings['knownoptions']) ) {
    			$knownoptions =  $optionsframework_settings['knownoptions'];
    			if ( !in_array($option_name, $knownoptions) ) {
    				array_push( $knownoptions, $option_name );
    				$optionsframework_settings['knownoptions'] = $knownoptions;
    				update_option('optionsframework', $optionsframework_settings);
    			}
    		} else {
    			$newoptionname = array($option_name);
    			$optionsframework_settings['knownoptions'] = $newoptionname;
    			update_option('optionsframework', $optionsframework_settings);
    		}
    		
    		// Add default options to the database
    		$values = array();
    		$config = optionsframework_options();
    		foreach ( (array) $config as $option ) {
    			if ( ! isset( $option['id'] ) ) {
    				continue;
    			}
    			if ( ! isset( $option['std'] ) ) {
    				$option['std'] = '';
    			}
    			if ( ! isset( $option['type'] ) ) {
    				continue;
    			}
    			if( $option['id'] != 'import_settings' 
    				&& $option['id'] != 'export_settings' 
    				&& $option['id'] != 'fonts_update_google'
    				&& $option['id'] != 'sidebar_create' 
    				&& $option['id'] != 'sidebar_list' ) {
    				$values[$option['id']] = $option['std'];
    			}
    			if( $option['id'] == 'sidebar_list' ) {
    				$sidebars = array();
    				$sidebars[] = Array( 'name' => 'Contact', 'id' => 'contact' );
    				$sidebars[] = Array( 'name' => 'Features', 'id' => 'features' );
    				$values['sidebar_list'] = $sidebars;
    			}
    		}
    
    		if ( isset($values) ) {
    			add_option( $option_name, $values ); // Add option with default settings
    			delete_transient( UNISPHERE_THEMEOPTIONS . '-enqueue_google_fonts' );
    			delete_transient( UNISPHERE_THEMEOPTIONS . '-skin-css' );
    		}
    	}
    	
    	// Update custom portfolio permalink structure
    	update_option('flush_rewrite_rules', '1');
    }
    ?>

    No sir, it is not a child theme.

    As far as I know, vanguard theme is not a child them.

    Thank you,

    –w–

    Plugin Author Mat Lipe

    (@mat-lipe)

    HI W,

    This code snippet is PHP

    function wptuts_scripts_with_jquery()
    {
        // I can register the script it for a theme:
        wp_register_script( 'custom-script', get_template_directory_uri() . '/js/custom-script.js', array( 'jquery' ) );
    
        // Enqueue the script:
        wp_enqueue_script( 'custom-script' );
    }
    add_action( 'wp_enqueue_scripts', 'wptuts_scripts_with_jquery' );

    And may be placed at the bottom of your theme’s functions.php

    Have a great day!

    Mat Lipe

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    For pro or commercial product support please contact the author directly on their site. This includes any pre-sales topics as well.

    As the author is aware, commercial products are not supported in these forums. I am sure they will have no problem supporting you there.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘How can a child menu be expanded by default?’ is closed to new replies.