The whole project can be found here Github.
I added a dynamic menu on my navigation bar placed in the header. For some reason I can't figure out how to link the dynamic menu with either a class or an ID defined in my style.css file.
For some reason, neither the 'menu_class' or the 'menu_id' seem to work.
Here the menu in the header.php file:
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<!--Container of my link that are on the far right, they collapse with a small screen-->
<ul class="nav navbar-nav navbar-right">
<!--This code inject the dynamic menu inside thge av bar-->
<!-- The Dynamic menu is managed in the admin section of word press-->
<?php
wp_nav_menu(
array(
/*must have this link to function.php
*In function.php we defined this menu 'alphamenu'*/
'theme_location' => 'top-right-menu',
/*this line of code removes the default menu appearence*/
'container' => false,
/*this line makes the menu with the same layout specified above
*(same as link 1 and 2)*/
'items_wrap' => '%3$s',
/*CSS class applied to the menu*/
'menu_class' => 'nav navbar-nav custom-head-foot',
'menu_id' => 'custom-dynamic-menu'
)
);
?>
</ul> <!--dynamic menu unordered list-->
</div> <!--dynamic menu div-->
The function.php file:
/*Function to register a custom menu for the admin section
*This resurces was taken from the wordpress codex*/
function custom_theme_setup() {
/*Registered a custom primary navigation menu*/
register_nav_menus (
array( 'alphamenu', __( 'Primary Menu 123') )
);
/*Add theme support for title tag*/
add_theme_support( 'title-tag' );
}
/*Hooking in the function "custom_theme_setup()" after the theme is setup
*surce: wordpress plugin api hooks*/
add_action( 'after_setup_theme', 'custom_theme_setup');
If the render method is screwed up you can always use .nav > div with or without pseudo-class like :nth-of-type(1) or there's second way: .nav:nth-child(1) as query for first child inside div.nav?
If you want to add class, try to add it within wp_nav_menu() you wrote like this:
wp_nav_menu(
array(
/*must have this link to function.php
*In function.php we defined this menu 'alphamenu'*/
'theme_location' => 'top-right-menu',
/*this line of code removes the default menu appearence*/
'container' => false,
/*this line makes the menu with the same layout specified above
*(same as link 1 and 2)*/
'items_wrap' => '%3$s',
/*CSS class applied to the menu*/
'menu_class' => 'nav navbar-nav custom-head-foot **add_your_class_within_single_quotes**',
'menu_id' => 'custom-dynamic-menu'
)
);
or you can apply selectors I wrote in first answer to your CSS.
Related
I created custom menu into my Wordpress site. I registered the new menu into functions.php file using this code:
// Add new Footer menu
function register_my_menu() {
register_nav_menu('new-menu',__( 'New Footer Menu' ));
}
add_action( 'init', 'register_my_menu' );
and after that inserted this line into footer.php file from current theme:
<?wp_nav_menu( array( 'theme_location' => 'new-menu', 'container_class' =>
'new_menu_class' ) ); ?>
and menu is showing into footer, but its showing into list view, and I want to show vertically inline in footer, of course centered is possible. I used CSS to add inline styling like this:
.new_menu_class {
display:inline-flex;
}
But seems do not many any changes to menu in footer. Any help here?
You're applying styles to the container of the wp_nav_menu function where the structure of the returned html is
<div class="new_menu_class"> <ul> <li>...
'container_class'
(string) Class that is applied to the container. Default 'menu-{menu slug}->container'.
https://developer.wordpress.org/reference/functions/wp_nav_menu/
For your CSS to be applied on the list items (I'm assuming you wish to have the horizontally). you will need to add this class under the arguments for 'menu_class'
'menu_class'
(string) CSS class to use for the ul element which forms the menu. Default 'menu'.
If you applied the same class in your question to the menu_class you could apply the following:
.new_menu_class {
display: flex;
align-items: stretch;
justify-content: space-evenly;
width: 80%;
margin: 0 auto;
padding: 0;
}
Looking at your site I can see you have a set width container with media queries, I would suggest the same when applying this so as your UI is clear when viewing on smaller devices.
I'm trying to get a different sidebar to load within child pages of a particular parent without the use of a plugin or setting up another template file.
This is what I have so far:
register_sidebars(1, array(
'name' => 'Other Sidebar',
'id' => "other-sidebar",
'before_widget' => '<li class="widget">',
'after_widget' => '</li>',
'before_title' => '<span class="widgettitle">',
'after_title' => '</span>'
));
if ( $post->post_parent == '1164' ) {
dynamic_sidebar( 'other-sidebar' );
}
But I'm wondering if I need use a filter of some sort to replace the default sidebar that is being loaded instead? Not too sure if that's correct or not.
Since you can edit the theme (or child theme) you could add a Page Template that would override the current page template with the custom sidebar you want.
<?php
/*
Template Name: Custom Sidebar Page // All versions
Template Post Type: page // 4.7+ only
*/
// Page code here with the sidebar you want...
?>
<aside id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'other-sidebar' ); ?>
</aside><!-- #secondary -->
Then, in the edit for your page and it's child pages, set this template as the one you want.
I have the following code which makes/inputs my navigation into my site. The links are created through the admin panel. I want to add a '|' separator in between the links
HTML
<?php wp_nav_menu( array( 'container_class' => 'main-nav', 'theme_location' => 'primary' ) ); ?>
functions.php
/* Register 'primary' navigation */
function wptutsplus_register_theme_menu() {
register_nav_menu('primary', 'Main Navigation Menu');
}
add_action('init', 'wptutsplus_register_theme_menu');
Current output
Link 1 Link 2 ...
Desired output
Link 1 | Link 2 ...
html
<div class='col-md-6'>
<?php wp_nav_menu( array( 'container_class' => 'main-nav', 'theme_location' => 'primary' ) ); ?>
</div>
Updated v2
You can use after parameter of wp_nav_menu(), with a small CSS trick.
Here is the code:
$menuParameters = [
'container_class' => 'main-nav',
'theme_location' => 'primary',
'menu_class' => 'my_custom_class', //<-- add this
'after' => '<span class="sep">|</span>' //<-- add this
];
wp_nav_menu($menuParameters);
Add this to you style.css
.my_custom_class li:last-child .sep{ display:none; }
Alternative way (with pure PHP approach)
$menuParameters = [
'container_class' => 'main-nav',
'theme_location' => 'primary',
'after' => '|', //<-- add this
'echo' => false //<-- add this
];
$nav_html = wp_nav_menu($menuParameters);
$needle = isset($menuParameters['after']) ? $menuParameters['after'] : '';
$index = strrpos($nav_html, $needle);
if ($index)
{
echo substr_replace($nav_html, '', $index, strlen($needle));
}
else
{
echo $nav_html;
}
All code is tested and works.
Hope this helps!
add the symbol |(as many as menu links you have) as u would add normally a custom link in the wordpress menu.
after that get the class or id of every element with devtools then apply this css to every one of the elements
.itemtofind{
pointer-events: none;
cursor: default;
}
you can customize the css element as you wish , add padding, color, etc.
in the past i made a web page with that feature and everything was right.
when you are in mobile apply the correct media query and hidde the symbols | with this css to the elements
display:none
I'm not super sure how wordpress styles their links, but this should emulate that, I don't think simply inserting the textnodes will work.
.wp-navigation {
border-right:2px solid black;
}
.wp-navigation:last-child {
border-right:none;
}
Use CSS. Something like this should work.
.main-nav a:after {
content: '|';
display: inline-block;
margin: 0 .5em;
}
I am currently going through Wordpress tutorials.
The pages that I have created here are all in Capatalized case (e.g. About us). During run-time I want them to automatically convert to upper-case (i.e. ABOUT US) instead of changing the page titles through the dashboard.
I am aware about the php's strtoupper() method however not sure where to apply this so that it dynamically changes the page titles to upper-case in the nav menu.
CODE in header.php:
<!-- Nav Menu -->
<nav class="site-nav clearfix">
<?php
$args = array(
'theme_location' => 'primary'
);
wp_nav_menu( $args ); enter code here
?>
</nav>
This code in the stylesheet should work:
nav.site-nav li {
text-transform: uppercase;
}
I am stuck and trying to figure out the Problem... in WordPress site
al-hussain
now the Problem is that,
i found a menu appearing on the home, i changed my menu..but when i clicked on pages just #
was the URL of All Pages but the page Contact-us has actual link, and the menu winch i created now appears in actual position..means when i goes to contact-us page and than my created menu is activated else,the default or static menu is appearing... even though i delete all my created menu but on loading site it shows menu...
default Menu is
and after clicking on contact us the menu is
here is header.php main_nav_menu
<!-- Begin main nav -->
<div id="nav_wrapper">
<div class="nav_wrapper_inner">
<div id="menu_border_wrapper">
<?php
if ( has_nav_menu( 'primary-menu' ) )
{
//Get page nav
wp_nav_menu(
array(
'menu_id' => 'main_menu',
'menu_class' => 'nav',
'theme_location' => 'primary-menu',
)
);
}
else
{
echo '<div class="notice">Please setup "Main Menu" using Wordpress Dashboard > Appearance > Menus</div>';
}
?>
</div>
</div>
</div>
any one can figure out ! please
Did you check your header.php file? I believe you have static menu there.
Here is the syntax to create a menu that you have created at the backend
<?php wp_nav_menu( array('menu' => 'main_menu', 'container' => '') ); ?>
Replace your static menu with the code above with the name changed in the 'menu' parameter
i sloved the Problem by Deleting the Cache, here i found directory
wp-content/cache/supercache/
thanks