Hi I have a problem with wordpress navigation tools. What I want to do is remove the containing class.
According to the documentation by setting 'containter' => false removes the containing class.
But the problem is when I have done so, nothing happened.
<?php wp_nav_menu( array( 'theme_location' => 'header-menu',
'container' => false
) ); ?>
But when the menu is displayed it is still enclosed inside a tag.
Do yo guys have an idea how to fix it?
I found the problem. I forgot to set Header Menu in the functions.php and in the admin panel as well.
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'footer-menu' => __( 'Footer Menu' ),
)
);
Make sure to use both and that in the admin panel the menus are set to the correct menu container.
Related
I have two themes installed on a wordpress website. I have moved all my non-theme specific functions into a plugin as recommended and all is working well except customizer.php which was included in my functions.php file. I moved it away from functions.php into the plugin. The customizer contents showed when first theme was activated but won't show when I switched to the other theme. Below are code snippets for reference:
I included customizer.php into my plugin using the code below
require( plugin_dir_path( __FILE__ ) . 'inc/customizer.php' );
Below is the panel that controls the logo
if ( class_exists( 'WP_Customize_Panel' ) ):
$wp_customize->add_panel( 'panel_general', array(
'priority' => 29,
'capability' => 'edit_theme_options',
'title' => __( 'General options', 'gswmi' )
));
/* LOGO */
$wp_customize->add_setting( 'site_logo', array(
'sanitize_callback' => 'esc_url_raw',
'transport' => 'postMessage'
));
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'themeslug_logo',
array(
'label' => __( 'Logo' ),
'section' => 'title_tagline',
'settings' => 'site_logo',
'priority' => 1,
)
)); endif;
The logo and contents show when the first theme is activated
But won't show when the second theme is activated
I have tried different fixes, even deleting the text domain in the customizer.php code, none seemed to work. I want to be able to switch themes and still be able to show the same contents in the customizer and the frontend irrespective of the theme activated. I will appreciate any help.
I was finally able to sort it, thanks to some articles I found online (credits below).
By default, my setting's type above is 'theme_mod'
Theme mods are stored in a single array in the options table in the database, one field per theme. In my case, i found all the theme customizations in a single array under theme_mods_(mythemename) in wp_options table in my database. As you can guess, this is not good for performance.
To make my logo and other settings readily availabe irrspective of the theme I use, I just had to change the setting type to 'option' from 'theme_mod' which is the default setting type.
But what’s the difference? To try to keep this simple:
Theme Modifications(Theme Mod) represent what’s available for a specific theme. WordPress saves all options managed by The Customizer as a single array in the database.
Options are available to any theme and/or any plugin. In contrast to the The Customizer, WordPress saves each value as a single record in the database.
Update code below
if ( class_exists( 'WP_Customize_Panel' ) ):
$wp_customize->add_panel( 'panel_general', array(
'priority' => 29,
'capability' => 'edit_theme_options',
'title' => __( 'General options', 'gswmi' )
));
/* LOGO */
$wp_customize->add_setting( 'site_logo', array(
'type' => 'option',
'sanitize_callback' => 'esc_url_raw',
'transport' => 'postMessage'
));
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'themeslug_logo',
array(
'label' => __( 'Logo' ),
'section' => 'title_tagline',
'settings' => 'site_logo',
'priority' => 1,
)
)); endif;
The above Setting’s value will get its own column inside the WP_OPTIONS table and there will be a performance boost when the value is accessed for outputting in the frontend.
Credits:
https://www.usablewp.com/learn-wordpress/wordpress-customizer/theme-mods-vs-options-in-wordpress/
https://tommcfarlin.com/wordpress-options/
I create wp_nav_menu for my header and footer but its always return same menu intended only for footer.
header
wp_nav_menu( array(
'theme_locaiton' => 'Top',
'menu_class' => 'top-side-navigation'
) );
footer
wp_nav_menu( array(
'theme_locaiton' => 'Footer',
'menu_class' => 'bottom-side-navigation'
) );
and this is my register for my menu
register_nav_menus( array(
'Top' => __('Head Navigation'),
'Footer' => __('Footer Selection'),
) );
I hoping to output for "Top" menu is
HOME, ABOUT, VISION, MISSION, CONTACT
and for the "Footer" is
ABOUT, VISION, MISSION, CONTACT
my problem is always return the "Footer" menu value
for "TOP" and "Footer"
'theme_location', not 'theme_locaiton'
Im trying to create a sub section within the customiser options in WordPress, so i have a new section called Typography and i want to make sub sections inside that which will be Heading 1, Heading 2 etc... those should open out into their own set of controls. However i have been looking through the codex and cant seem to find a way to link those menus up, any ideas?
Below is the normal code for adding a section but adding a new one doesnt seem to have a option for attaching it to the parent? Ive tried a few variations of the code below without any luck, all i get is 2 typography menus on the main menu.
EDIT: Still having no luck, i read in the codex about a option for panels but cant seem to implement it.
i am using the code below, its just a simplified version of the code to make sure i have it right. I assume a section goes into the panel and the settings and control go into the section. Using this codex
// ADD PANEL
$wp_customize->add_panel( 'typography_panel', array(
'priority' => 10,
'capability' => 'edit_theme_options',
'theme_supports' => '',
'title' => 'Typography',
'description' => 'contains options for all font settings on the website.',
) );
// ADD SECTION TO GO INTO PANEL
$wp_customize->add_section( 'heading_1', array(
'priority' => 20,
'capability' => 'edit_theme_options',
'theme_supports' => '',
'title' => 'H1 Options',
'description' => 'all options for heading 1 font.',
'panel' => 'typography_panel',
) );
// ADD SETTINGS
// Selector Background - Highlighting
$wp_customize->add_setting(
'typography_highlight_background_h1',
array(
'default' => '#333948',
'sanitize_callback' => '',
) );
// ADD CONTROLS
// Highlight Background for Browser
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize, 'typography_highlight_background_h1',
array(
'label' => __( 'Highlight Background', 'typography_highlight_background_h1' ),
'section' => 'heading_1',
'settings' => 'typography_highlight_background_h1',
) ) );
You're looking for add_setting and add_control. Sub-sections can be added by passing the name of the section as an argument to add_control.
I'm using a theme and added the polylang plugin to make the site multilingual. And it's quite confusing to make the menu multilingual.
wp_nav_menu( array(
//'theme_location' => 'header-menu',
'theme_location' => '',
'menu' => 'id',
'orderby' => 'menu_order'
));
In my header I have this wp_nav_menu() function. When using this option 'theme_location' => '' the order of the menu is correct but is not switching when clicking on the second language flag. Using this option: 'theme_location' => 'header-menu' changes menu when clicking on the flags but the menu items aren't in the correct order. In the wp dashboard under appearence menus there are two menus and the polylang settings for these seems to be correct. Anyone knows what's causing the problem and how to fix it?
Problem solved. I was using a theme which had this line of code in it's functions.php:
register_nav_menus( array(
'primary' => __( 'Primary Navigation', '<theme_name>' ),
) );
So I had to use:
'theme_location' => 'primary'
in the wp_nav_menu function.
in file functions.php:
function themeaw_setup() //my theme name themeaw
{
add_theme_support('menus');
register_nav_menus(array(
'header-menu' => 'Header Menu',
'footer-menu' => 'Footer Menu'
));
}
add_action('after_setup_theme', 'themeaw_setup');
//add_action('init', 'themeaw_setup');
i try add action 'after_setup_theme' or 'init' but nothing changed. Menu is not created. What's wrong? Somebody can help me?
You only need to put this:
function themeaw_setup(){
register_nav_menus(array(
'header-menu' => 'Header Menu',
'footer-menu' => 'Footer Menu'
));
}
add_action('init ', 'themeaw_setup');
With this you can customize the menu in the theme menu options and to display you can do it with for example in the header.php
<?php wp_nav_menu (array('theme_location' => 'header-menu','menu_class' => 'nav'));?>