Menu is not showing in admin panel - php

I try to make my own theme in wordpress. Stucked a problem: i can't see menu button in admin panel. I've registered menu in functions.php of my theme
<?php
register_nav_menu( 'menu', 'Menu on the main page' );
?>
But there is no menu button appear in admin panel - appereance. I did all that was recommended on youtube video (https://youtu.be/I0zu6Dc3JDI?t=95). Nothing. Please help =) I have last version of Wordpress.

You was half way there, you had the right idea for registering the menu however you missed out telling WordPress to run your register menu command.
What you need to do is wrap it in a function and call the function on 'init' which is the initialisation of the admin area (one of many WordPress hooks), see below:
function register_child_menus() {
register_nav_menus(
array(
'my-menu' => __( 'My Menu' )
)
);
} add_action( 'init', 'register_child_menus' );

Related

How to create and customize a menu in word press 5.8 by coding

I'm new to word press. For creating a new menu, I'm using register_nav_menus()
function inside functions.php to register a menu. But I still need word press admin panel to add items in a menu e.g contact, about us pages. How can I add these options by coding instead of using admin panel of word-press.
function register_menu(){
register_nav_menus(
array(
'primary-menu' => 'Primary Main Menu',
'footer-menu' => 'Footer Menu'
)
);
}
add_action('init', 'register_menu');

WordPress add_menu_page not showing in backend

I am trying to create a custom plugin using the code below but the tab/link to the page is not appearing in the WordPress Dashboard and I'm not sure what I'm doing wrong. My company-admin.php file is located in my plugins folder inside a folder called company-admin. The file permissions for the php file are 644 incase that is relevant. Can you help?
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
add_menu_page(
'Company Admin',
'Company Admin',
'manage_options',
'company-admin/company-admin.php',
'',
'',
6
);
}
I'm unsure if this is the correct way to navigate to my plugin but I used this link, correct me if its the wrong link;
https://mywebpage.uk/wp-admin/admin.php?page=company-admin%2Fcompany-admin.php
And what I get is the following error;
Sorry, you are not allowed to access this page.
Query Monitor
The message above was triggered by Core.
Call stack:
wp_die()
wp-admin/includes/menu.php:348
the permission file in wordpress must be 755 for work correctly.
For develop a plugin follow the wordpress official guide https://developer.wordpress.org/plugins/intro/
Let me know.
Try to add more code to your path. Instead of 'company-admin/company-admin.php', paste 'your_plagin_folder/company-admin/company-admin.php',
Edited
But more cleanest is using that way:
function wpdocs_register_my_custom_menu_page(){
add_menu_page(
'Custom Menu Title',
'custom menu',
'manage_options',
'custompage',
'my_custom_menu_page',
'',
6
);
}
add_action( 'admin_menu', 'wpdocs_register_my_custom_menu_page' );
/**
* Display a custom menu page
*/
function my_custom_menu_page(){
//print all what you need or include any pages
include_once plugins_url('company-admin/company-admin.php', __FILE__);
}

Wordpress custom theme: Widget area not configurable in Customizer

I am currently developing a custom wordpress theme for my own website to use. My main concern is to include widget areas. I managed to include a widget area so that it is configurable from Appearance > Widgets and the result also shows up in the customizer preview and on the live website.
The only problem is that I am not able to configure the widgets from within the customizer. When I click on Widgets in the customizer, it only shows this message:
Your theme has a widget area, but this particular page doesn’t display it. You can navigate to other pages on your site while using the Customizer to view and edit the widgets displayed on those pages.
Well, since the under Appearance > Widgets configured widget is actually showing, my site seems to have a widget area. But I guess something is missing for the customizer to know that.
Here is the code registering the sidebar / widget area that I took from many similar tutorials:
<?php
function tgf_customize_register( $wp_customize ) {
//All our sections, settings, and controls will be added here
}
add_action( 'customize_register', 'tgf_customize_register' );
function tgf_widgets_init() {
register_sidebar(array(
'name' => 'Sidebar Widget',
'id' => 'main_sidebar_widget',
'description' => 'Widget Area',
'before_widget' => '<div class=”widget”>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'tgf_widgets_init' );
?>
This is the code displaying the sidebar:
<?php if ( is_active_sidebar( 'main_sidebar_widget' ) ) : ?>
<?php dynamic_sidebar( 'main_sidebar_widget' ); ?>
<?php endif; ?>
I also tried showing it with this code, but then the widget doesn't show on the site at all, even when I configure it from Appearance > Widgets:
<?php if ( is_active_sidebar( 'main_sidebar_widget' ) ) : ?>
<?php get_sidebar( 'main_sidebar_widget' ); ?>
<?php endif; ?>
Why can't I configure this widget from within the customizer?
This question WordPress theme creation : There are no widget areas on the page shown mentions the same error message in the customizer, but does not provide a solution that applies to my specific problem.
Since I couldn't find anything by researching this problem, I think I am missing something fundamental. Which could very well be, since I'm new to wordpress theme development and PHP. Thanks in advance!
Found out myself what none of the tutorials told me:
I have to add <?php wp_head() ?> at the start of the page and <?php wp_footer() ?> at the end of the page.
Wordpress seems to need these hooks in order to function properly.

Wordpress Custom Navigation on Secondary Theme

I've followed the codex; http://codex.wordpress.org/Navigation_Menus
However I believe that because we are trying to do the edits on page that isn't using the main sites theme, it's falling apart.
Our standard theme is Grand College, the theme however we are trying to edit is a BlankSlate theme.
I've made the edits in the BlankSlate functions file and inserted:
function register_my_menu() {
register_nav_menu('example-menu',__( 'EXAMPLE Menu' ));
}
add_action( 'init', 'register_my_menu' );
In the header file I've inserted;
<?php wp_nav_menu( array( 'theme_location' => 'example-menu' ) ); ?>
And in the WP-admin dashboard I've built a menu for 'example': I've added Home and Contact to it. However in the 'Manage Location' section I've only got 2 menu options which is what Grand College gives you by default
However when I view the site, I get the 'main' navigation showing rather than just the example menu.
Do my edits to put a new custom menu in, have to be done on the Grand College theme (The sites standard theme, or am I right to be trying to edit the pages theme?
Any help would be great appreciated.
To register a navigation menu i simply used the following code-
register_nav_menu('example-menu',__( 'EXAMPLE Menu' ));

How to add a new header menu in wordpress?

How to add a new header menu in wordpress?
You may add a function to wordpress (well anywhere in your theme) using the wp_nav_menu(). This requires that you add the code below to your functions.php file (if you do not have one in your theme directory then create one):
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
'menu-1' => __( 'Top menu' ),
'menu-2' => __( 'Bottom menu' )
)
);
}
Change the "Top menu" and "Bottom menu" to what ever you want the names to be. Basically you are just telling wordpress (wp 3.+) to make reservations for these menu in your theme. If you want more you just need to define the names in a new line. Save that.
That done you will need to add the menu in your site template. Usually I define the arguments first before I call the wp_nav_menu() function. Read up on the arguments here http://codex.wordpress.org/Function_Reference/wp_nav_menu
Hope that helps.
You can manage the menus in your WordPress dashboard under "Appearance => Menus". Here is a tutorial: http://en.support.wordpress.com/menus/

Categories