That code should work. Are you usign “myclass” as the class and not “.myclass”?
Is this for a specific use where class will always be the same? If you’re only looking to ever use this on one place, you can do this:
function print_menu_shortcode($atts, $content = null) {
extract(shortcode_atts(array( 'name' => null, 'class' => null ), $atts));
return wp_nav_menu( array( 'menu' => $name, 'menu_class' => 'myclass', 'echo' => false ) );
}
add_shortcode('menu', 'print_menu_shortcode');
Then change the section ‘menu_class’ => ‘myclass’ with the class you need. this will avoid having to use the class. Again, don’t use the “.” in front of the class here.
Short code usage:
[menu name="menu_name"]
Related Posts:
- Solution to render Shortcodes in Admin Editor
- Use AJAX in shortcode
- Include PHP file in Content using [shortcode]
- Shortcode producing headers already sent error
- How to add attributes to a shortcode
- How to display random users with avatars
- Enabling shortcodes for custom fields
- How to use get_media_embedded_in_content function
- Can shortcodes contain conditional statements? Even without them my shortcode renders blank page
- Shortcode with parameters inside parameters
- What is wrong with this Shortcode? I get it in a wrong place inside the content
- Display random text from a file with the WP built-in AJAX API
- Set first oembed in post to a global variable or function
- Remove images from get_the_excerpt
- Shortcode with custom content attribute?
- Passing HTML in WordPress Shortcode arguments
- Display a text message if the shortcode is found?
- Custom Shortcode, functions PHP WP_Query loop
- Super simple shortcode not working
- How to extract the variables out from “add_shortcode” function?
- Display first name of logged in user?
- How to get specified parent page title in my function
- Possible to display shortcode based on the category?
- Shortcode pagination not advancing
- Having issues with a foreach inside of a shortcode with ACF gallery
- Shortcode inserts paragraphs before and after executing shortcode
- Display post shortcode content in the sidebar?
- How to get the index number of the posts?
- Using shortcode content with nested shortcode
- How to filter $content in shortcode function
- Create a custom taxonomy that will be used to create and filter markers in a Google Map
- Display gallery on bottom after content
- Add button to kitchen sink toggle
- WordPress Shortcode function display outside of widget
- check if the user is owner of current page
- Help With Creating Shortcode
- Use html inside shortcode function
- Shotcode argument issues
- Shortcode parse error – wrong syntax
- Exclude category from shortcode
- get_pages() Returns Only One Item
- Function shortcode – Set Parameter
- Adding an option to a shortcode
- How to use author meta in shortcode?
- Testing for a shortcode using a function. 404 page throwing PHP Notice
- Use a shortcode to display custom meta box contents
- Woocommerce checkout field
- How can I pass a shortcode value to the head in wordpress functions.php
- Native gallery custom html output
- dynamic site link for future migration in echo do_shortcode()
- How to create shortcode with html and php content?
- Tracking the number of shortcodes for a list?
- Need a method to prevent WP from adding in between my shortcodes
- Load scripts for do_shortcode( ‘ [ my_shortcode ] ‘ )
- Can I include a custom PHP function in a WordPress function?
- How to create a shortcode out of a php function
- Shortcode of a function
- How to add a shortcode to call a function
- How can I call a PHP function inside a hardcoded shortcode?
- Problem with shortcode inside a shortcode
- Need help making a short code work
- Using One Function To Create Two Different Shortcodes
- Is it possible to create a shortcode to link to a specific post/page where the tag is just an attribute?
- How to add if statement on WordPress shortcode output
- Pagination not working – FrontPage
- page shows short code not output
- Function to function shortcode help [closed]
- Last updated posts shortcode in functions.php
- I want to display the sku in the product pages of my EDD website
- Shortcode to insert default text and change one word throughout it?
- use add_action in a shortcode (gravity form – WordPress)
- Shortcode displaying outside the div [duplicate]
- Shortcode Initialization in a Custom Theme
- Shortcode with pagination advancing multiple queries
- Show users last read posts for each user?
- Get shortcode attribute value to another function
- How to retrieve image IDs from shortcode content?
- Display list of pages that contain a certain string within the slug
- Hide disclaimer from summary excerpts
- Function not receiving string from shortcode
- How To Show Shortcodes In WordPress Custom Fields?
- Shortcode to eliminate and replace with
- Can I use a function to return HTML and the result of another function?
- Problem in outputting shortcode
- How to display data from custom fields in my custom shortcode?
- Modify function Shortcode_atts
- Shortcode to output get_header not working
- restrict access to specific urls on a specific period of time
- using enqueue_script in a shortcode isn’t working
- Add title & subtitle to shortcodes
- Shortcode Variations?
- Shortcodes not outputting in correct divs
- shortcode inside post called by ID does not render as expected
- Custom shortcode not being included in content paragraph [duplicate]
- trouble with passing class method data to outside function
- Get term count on a category page
- How do grab the main loop, with conditions, and output via shortcodes
- Display function from functions.php in tag.php
- Creating mixture of shortcodes to use in the visual/text editor
- multible shortcodes (for differnt values) with one function