WP nav menu bug - css

I have used WP nav menu in my website. It works fine. I have added the sub link under the home link. But it is not properly displayed. Please refer the screenshot.
In the above image, "support our work" sub link is fine. But the Home sub link is not properly displayed. I need "News, Calendar, Like Us On FaceB" displays under the HOME link similar to "Support our work". Home Page does not accept the sub links.

When you have a static page as home page it is possible.
Go to Settings, Reading, Front page displays. Then select your "Front page", that will appear in the menu as the home link.
Then in functions.php of your theme add this code:
function my_page_menu_args( $args ) {
$args['show_home'] = false; // Do not show 'home' link in the menu.
return $args;
}
add_filter('wp_page_menu_args', 'my_page_menu_args', 1000);
In the menu, the subpages of the selected page, will now appear as submenu items.

Try to add theme_location => 'secondary'

Related

Customizing my account page in woocommerce wordpress

When I customize the my account page in woocommerce, I can edit right side section by creating my_account.php inside my account folder in woocommerce. But In left side it is showing "Define your 'My Account' navigation Apperance > Menus",
After seeing this I tried to create menu called "My account", but there was no theme location existing, so I create a theme location called "my account menu". And I assign "my account" menu with theme location "my account menu".
I don't know how to connect this menu to my account page in woocommerce, the page again showing same "Define your 'My Account' navigation Apperance > Menus".
Try Appearance>Menus>Custom Links
Otherwise:
Is the theme you are trying to edit a pre-built theme?
Is the platform up-to-date or outdated (sometimes updates/bugs can alter functionality of pre existing code)?
Sometimes there are errors in the theme build, as I have seen. In such a case, I would recommend reaching out to the theme developer(s) as they can usually help the best in this situation. If not, check back. Hope this helps.
Call menu by menu name instead of theme_location
<?php wp_nav_menu( array( 'menu' => 'Main Menu' ) ); ?>

Customizing the 'read more' link in Wordpress

Im trying to work on this site and I need to change the link in the "read more" button to another page (See picture, red circle).
How do I customize the destination of the "read more" link? This isn't an excerpt function, it is a clickable link that leads to a whole other page.
This will add a link in a div after the excerpt. Hide the initial read more link and that should work. Although the read more link really was intended only to link to the full article.
function add_excerpt_link($more) {
global $post;
return 'Custom Link;';
}
add_filter('excerpt_more', 'add_excerpt_link');

How to stop showing menu in static home page wordpress

Ok, I'm creating a wordpress theme. I don't want my navigation menu to show in the home page "Only" if the site admin setup Front page displays > A static page (select below).
otherwise I want to show the menu in home page & other pages too. I've used this <?php if(!is_front_page()):?> function, but it is not working.
some one suggest me <?php if(!is_home()):?>, but it is not working either.
So how do I make it work?
Please follow the below steps:
Dashborad > Settings > Reading
Select A static page (select below) option in Front page displays section.
Select the page you want to display from Front Page drop down box.
In header.php in the code for displaying menu, make the alteration as below.
if ( ! is_page( '{slug of the selected page in Front Page drop down box}' ) ) {
//enter your code to display menu here
}
?>

How to hide menu only on Home page wordpress

I m using a one page theme. I would like to disable or choose not to show the menu on the home page. But when user scrolls down to the next page the menu should become fixed. I have removed the menu from the home page now, however i'm not able to get the menu to be fixed on top for the other pages.
Please advice.
You can also go the CSS way.
WordPress adds a class home to the body attribute in home page. You can target that particular attribute to hide the menu as shown below.
.home .menu-class-name{
display:none;
}
This will hide the menu from home page but will show it on other pages
Note - replace .menu-class-name with your own menu class
you can do it some thing like the below code:
<?php
if(is_front_page())
{
//Just comment out the menu section
}
else
{
//write your code to show the menu section
}
?>

Custom set "current-menu-item" class for specific pages in WP

I'm creating a custom WP theme and I'm using the Wordpress navigation bar. When switching between different pages, WP adds a "current-menu-item" class to link in navigation bar which corresponds to the current page.
However, if that page/post is not present in the nav bar, it doesn't add the "current-menu-item" to any of the nav bar items.
My problem is, when a user visits the page "BLOG" (which is actually a category page) and clicks on a certain post which opens the single.php template, I want the nav bar item "BLOG" to be underlined as it would if the visitor was visiting a blog page.
Sometimes I will want another nav bar item to be underlined when landing on SINGLE, depending on where the user came from (I also have homepage posts, then I'd like HOME to be underlined)
How do I accomplish this? Thanks.
You can use a filter and check what page you are currently on using conditional statements and add classes before the menu gets displayed:
function add_custom_classes($classes, $item){
if(is_single() && $item->title == 'BLOG'){
$classes[] = 'current-menu-item';
}
return $classes;
}
add_filter('nav_menu_css_class' , 'add_custom_classes' , 10 , 2);

Resources