I'm a WordPress beginner working on a local server I set up with MAMP. I created the style, index, footer, header and functions docs, and PHP assembled everything with no problems. The website published all my files as expected. Then I tried to add custom menus to the appearance panel / menus in the admin dashboard, but they wouldn't show up.
Here's a snapshot of my folder hierarchy:
And here's a screenshot of the admin page:
And this is all the code in my functions.php file so far:
<?php
function macsc_script_enqueue() {
wp_enqueue_style('customstyle', get_template_directory_uri() . '/css/macsc.css', array(), '1.0.0', 'all');
wp_enqueue_script('customjs', get_template_directory_uri() . '/js/macsc.js', array(), '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'macsc_script_enqueue');
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'extra-menu' => __( 'Extra Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
I've read several stack overflow threads and consulted the WordPress Codex support documentation. The register_my_menus function was a direct copy and paste from the WordPress doc. As far as I can tell, I'm doing everything correctly (obviously not, of course).
One thing that seems odd to me is that there were already tabs for "widgets," "menus" and "header" in the Appearance panel. Considering this is a custom theme that started with an empty folder, I'm not sure why those are there at all.
Any help would be greatly appreciated.
Typically menus are registered on the after_setup_theme hook. I'd try using that instead of init.
Also you don't need to register custom widgets or widget area support for the Widgets menu to show up, there's a lot that WordPress introduces in the core, regardless of your theme or active plugins.
And on second glance, it appears the TwentySeventeen theme is active, considering the Top Menu and Social Links Menu are the default menus in the TwentySeventeen (default) theme.
From TwentySeventeen/functions.php:
register_nav_menus( array(
'top' => __( 'Top Menu', 'twentyseventeen' ),
'social' => __( 'Social Links Menu', 'twentyseventeen' ),
) );
Go to Appearance > Themes and make sure your custom theme is activated.
I always register the menu in this way:
if ( !function_exists( 'theme_setup' ) ) {
function theme_setup() {
/*
* Some settings functions
*/
register_nav_menus(
array(
'header-menu' => __( 'Header Menu', 'domain' ),
'extra-menu' => __( 'Extra Menu', 'domain' )
)
);
}
}
add_action( 'after_setup_theme', 'theme_setup' );
Related
I am trying to add a menu for my new WordPress theme, what I want to happen is, the menu to be added to the registered menu location by default instead of having to go to the dashboard and selecting the menu that I want to make appear there.
I have looked at several tutorials and they all add the menu manually
This is the functions.php file which has the location registered.
register_nav_menus( array(
'main-menu' => esc_html__( 'Primary Menu', 'tester' ),
'footer-social-menu' => esc_html__( 'Social Menu', 'tester' )
));
And I call this using
<?php wp_nav_menu(array('theme_location' => 'footer-social-menu')); ?>
But WordPress still didn't show the menu by default in
Customizing ▸ Menus View ▸ All Locations
The Social Menu Area still says
---Select---
Can this be done?
(Note: The Menu is there, I just have to select it manually, i.e the menu area and the menu are successfully registered and working)
I got this to work
<?php
wp_nav_menu(array(
'theme_location' => 'footer-social-menu',
'menu' => 'Social Menu',
'fallback_cb' => false
));
?>
By Adding
'menu' => 'Social Menu',
as shown when calling the created Menu
I am trying to get a menu with few links, and show their/link/page featured image. following is my code for functions.php.
function register_my_menus() {
register_nav_menus(
array(
'main-menu' => __( 'Main Menu' ),
'useful-links' => __( 'Userful Links' )
)
);
}
add_action( 'init', 'register_my_menus' );
and this is where i am calling it in the page.
<?php wp_nav_menu( array( 'theme_location' => 'useful-links', 'sort_column' => 'menu_order', 'container_class' => 'useful-links', 'menu'=>'Posts Menu' ) ); ?>
i know something is missing but kindly advice. my page look and feel allow 6 links and their images.
thanks
This should be in your functions.php to register the menu within WordPress.
if (!function_exists('wp_basicTemplateSetup')) {
function wp_basicTemplateSetup() {
// Register the Main Menus into WordPress
register_nav_menus(array(
'primary' => __('Main Menu', 'theme-name'),
));
}
}
add_action('after_setup_theme', 'wp_basicTemplateSetup');
In your theme, where the menu is sitting you need to tell the menu function, which menu to look for. So..:
// Variable that tells WordPress which menu to use, look at "Theme Location"
// Put this variable either at the top of your theme, of right *before* the function wp_nav_menu
$mainmenu = array(
'theme_location' => 'primary',
'container' => false,
'menu_class' => 'some-menu-css-class',
'depth' => 2
);
// The WordPress menu function
<?php wp_nav_menu($mainmenu); ?>
These 3 components are necessary to get your WordPress menu working.
I am running a Avada theme together with WooCommerce on a wordpress site.
The issue is that I'm trying to get a search function on the top of the page, but only in responsive mode (on mobile devices). I've been able to add a third option for a sidebar in woocommerce. this shows up in the config (where to choose which widgets should go in). But I can NOT get it to show.
I know that you get the original sidebars like this (copied directly from original archive-product.php):
<?php
do_action( 'woocommerce_sidebar' );
?>
So I figured it should be possible to call for our own sidebar with the following line :
<?php
do_action( 'woo_sidebar-3' );
?>
This does not work though.
Since this has to be able to be shown only on responsive devices we used a custom css option of fusion to hide the other sidebars the following way :
#media only screen and (max-width: 720px) {
#sidebar {
display: none;
}
}
Which of course is too simple since it would block ALL sidebars. But that's something we could easily change. So far, the 3rd sidebar that we created does not show on responsive nor on desktop versions of the site. while the others do show on the desktop but not on the responsive (as desired).
EDIT-:
So i tried this with the following code :
<?php if ( !function_exists('dynamic_sidebar') ||
!dynamic_sidebar('woo_sidebar_3') ) { ?>
<p>Oops... this displays if the topbar is not set up</p>
<?php } ?>
It shows the error as given in the code, so it tries to pull the sidebar as we created. But it doesn't show. Is it because the following might not work correctly? :
'woo_sidebar_3' => array(
'label' => esc_html__( 'Global WooCommerce Product Sidebar 3', 'Avada' ),
'description' => esc_html__( 'Custom sidebar 3', 'Avada' ),
'id' => 'woo_sidebar_3',
'default' => 'None',
'type' => 'select',
'choices' => $sidebar_options,
'active_callback' => array( 'Avada_Options_Conditionals', 'is_woo' ),
Which was copied from the one right above that, which is called woo_sidebar_2?
EDIT 2 -:
Here is a JSfiddle with the complete sidebars.php code in it, and the dynamic_sidebar code (as HTML). the error I was pointing at is also visible when you run te script.
I'm not familiar enough with the Avada theme to know what some of those options mean and your block of code doesn't show the register_sidebar() call even though Avada must be using it.
To make things simpler, you could use standard WordPress code for registering a widget area
In your theme (ideally a child theme) add:
function so_38033924_widgets_init() {
register_sidebar( array(
'name' => __( 'Global WooCommerce Product Sidebar 3', 'your-theme' ),
'id' => 'woo_sidebar_3',
'description' => __( 'Custom sidebar 3', 'your-theme' ),
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'so_38033924_widgets_init' );
You would need to make sure the before_widget, before_title, type of parameters match the parent theme so that your widget will get the same styling.
And then your template code looks right to me:
<?php if ( !function_exists('dynamic_sidebar') ||
!dynamic_sidebar('woo_sidebar_3') ) { ?>
<p>Oops... this displays if the topbar is not set up</p>
<?php } ?>
I installed wordpress Genesis theme for my website. Currently, the home page lists down all the recent posts together from different categories.
I want to remove showing all posts haphazardly and install a category wise post slider in my homepage where under each category segmented posts will be shown which the users can scroll horizontally.
I found out this plugin but don't know how to use it in my theme. It would be helpful if someone knows a similar plugin also.
Here is my genesis theme home.php file content
<?php
/* I added this code for that plugin */
echo do_shortcode( '[wpsc_categorywise_slides]' );
//* Add Genesis grid loop
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'eleven40_grid_loop_helper' );
function eleven40_grid_loop_helper() {
if ( function_exists( 'genesis_grid_loop' ) ) {
genesis_grid_loop( array(
'features' => 0,
'feature_image_size' => 0,
'feature_image_class' => 'alignleft post-image',
'feature_content_limit' => 0,
'grid_image_size' => 'grid-featured',
'grid_image_class' => 'grid-featured',
'grid_content_limit' => 250,
'more' => __( '[Continue reading]', 'eleven40' ),
) );
} else {
genesis_standard_loop();
}
}
//* Run the Genesis loop
genesis();
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce_payu_in' ),
'type' => 'checkbox',
'label' => __( 'Enable PayUMoney', 'woocommerce_payu_in' ),
'default' => 'yes'
)
);
}
I am getting this code from pay-u plugin. Using this code I want to create my own admin panel, but I don't understand what this code means.
This is the tutorial page of wordpress where you can find a solution to add a admin page.
https://codex.wordpress.org/Administration_Menus
Wordpress Information:
Here is a very simple example of the three steps just described. This
plugin will add a sub-level menu item under the Settings top-level
menu, and when selected, that menu item will cause a very basic screen
to display. Note: this code should be added to a main plugin PHP file
or a separate PHP include file.
This is the wordpress example code:
<?php
/** Step 2 (from text above). */
add_action( 'admin_menu', 'my_plugin_menu' );
/** Step 1. */
function my_plugin_menu() {
add_options_page( 'My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options' );
}
/** Step 3. */
function my_plugin_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
echo '<div class="wrap">';
echo '<p>Here is where the form would go if I actually had options.</p>';
echo '</div>';
}
?>