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.
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/
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 fairly new to Wordpress and am trying to do something very specific. I am currently using the awesome html5blank to create my custom theme. I am using the native menus for my nav tabs. I am currently using background-image's to make my nav tabs images instead of text but that is posing problems with what I'm trying to achieve w/ css and making it responsive.
I want to be able to add <img> tags( different image for each <li> ) in my <li>'s via HTML.
As far as I've been able to find and read up, I need to create a custom structure in this found in my function.php file?
function html5blank_nav()
{
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
}
Please let me know what else I need to provide to make this question make more sense and help you get me on the right track. Thanks in advance.
It does not work that way. There are few options to do it:
Use CSS background. Each menu item will have some shared classes, also a unique class name you can work with, enough for you to add different background image for each. Read the Codex for more.
Well, if you REALLY need to add inline <img>, it doable but I would not recommend. Go to Appearances > Menus, and add a custom link to menu, and insert your <img> tag into the Navigation Label box.
OR simply don't use wp_nav_menu(), hard code your menu instead.
I'm new to Drupal so bear with me. I'm using the Omega theme (http://drupal.org/project/omega) and created a custom menu to use as the main menu. In the template I'm using this to get and display the menu:
<?php print theme('links', array('links' => menu_navigation_links('menu-omega-main-menu'), 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix', 'main-menu'))));?>
When I go to view the site, the menu shows, however the children menu links do not get rendered. I also attempted this:
<?php print theme('links', array('links' => menu_navigation_links('menu-omega-main-menu',1), 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix', 'main-menu'))));?>
to try to set the level depth the menus are rendered but then doesn't show at all.
To the first question that most people will try to ask, yes I have 'Show as expanded' checked.
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.