menu highlight current post - wordpress

I´m using a wordpress default installation with a very basic theme. The problem I have is that when I´m viewing a post, a normal post or a custom post type, the menu does not get highlighted.
For example, I click "Blog" and the blog posts archive page shows and the menu is still highlighted properly, but when I open a random post the menu highlight is gone.
is there any fix for this?

Coincidentally, I set something up for this yesterday for a client's theme. You probably have a class for highlighting the menu item? Can you post what your theme code looks like--probably this is in something like header.php within the theme.
What I did was compare the title of the page with the menu item, and set that class. Something like:
class="<?php if(trim(wp_title("",false))=="Home") echo "active"; ?>"
which sets the class to "active" if the wp_title is "Home". This is a static navigation menu with links for each page; yours might be dynamic within a loop printing the page titles for navigation, so it would be good to see your code to be able to help.

or you can have a condition,
<?php if (is_single() ?>

For highlighting a particular menu,you can try this in ur style.css file of your website:-
#nav li.current_page_item a{
color:#fff !important;
background-color:#82bd42;
text-decoration:none;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
padding:10px 10px;
}
Where nav is the id of the <nav id="id"> tag where menu is being located in
header.php,like this:-
<nav id="nav">
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
</nav>

Related

Remove page title from Woocommerce shop in Wordpress

i'm trying to remove the page title from my woocommerce shop page. If i use this css the page title is removed from all pages, this is not what i want.
.page-heading h1 {display: none;}
So i started looking for a page-id, but it seems the shop is a post, so i used postid of my page
.postid-15169 .page-heading h1 {display: none;}
but this doesn't work at all
i also tried to put this is my functions.php
add_filter( 'woocommerce_page_title', false);
But this doesn't do anything either. I guess it's not the shop title i'm needing to remove, just the page title.
Any idea what i can do to remove the title for this page only ?
you can find the page here: https://goo.gl/5LNwRR
I added a ccs code:
.page-title-shop h1 {
display: none;
}
It worked for Woocommerce 3.2.x
Instead of using css, you can use woocommerce filter to get the job done.
function wc_hide_page_title()
{
if( !is_shop() ) // is_shop is the conditional tag
return true;
}
add_filter( 'woocommerce_show_page_title', 'wc_hide_page_title' );
You can remove titles from all woocommerce pages. Here is a blog post about this.

Making a page in wordpress that doesn't affect the other pages

The problem is that all the pages have a content_container of a set width of 1056px and I want all pages to have the 1056px set width except for the home page in which I need a content container that spans over the whole page from left to right.
Look at the CSS class on the BODY tag that WP uses on either page. Write your own CSS targeting the page you want.
add a class to the body of all the files (index.php and page.php) like this:
<body <?php body_class(); ?>>
and then target the home page with css:
body.home #content_container{width:100%; !important}
#content_container{width:1056px;}
You can do it like this also:
<?php
if ( is_home() ) {
//This is Home page
echo '<div id="content_container_wide">';
}
else {
// This is not a homepage
echo '<div id="content_container">';
}
?>

Add class to category Wordpress

I want to add a class to my css if a category is displayed but I can't get it to work.
I added this to my header:
if ( is_category('areas')) { echo ' class="myclass" '; }
I want to add this class to my stylesheet to any page in this category so It changes the look of any page in that category. It isn't working though.
Ive read through a lot of the codex and this is all I can figure to do
Any suggestions?
Probably easiest to up WP's bodyclass; that will put in all the body classes you will need. With
<body <?php body_class(); ?>>
in header.php, it will output something like
<body class="archive category category-my-category-name category-1 logged-in">
The call that class in CSS, i.e.
body.category-my-category-name #my-div {background-color:#fff;}
See http://codex.wordpress.org/Function_Reference/body_class

WordPress Admin Nav Showing in Frontend

Anyone know how to remove the admin navigation links from the frontend? I've built a custom theme and when I am logged in to WordPress, WordPress is appending the admin nav bar somewhere.
The admin bar?
Go to Users > Your Profile > Show Admin Bar. Here you can disable it from your theme. If you want to completely disable (remove) it, use one of various plugins, like this.
Or you can remove it by default in functions.php.
/* Disable the Admin Bar. */
add_filter( 'show_admin_bar', '__return_false' );
<?php function yoast_hide_admin_bar_settings() { ?>
<style type="text/css">
.show-admin-bar {
display: none;
}
</style>
<?php }
function yoast_disable_admin_bar() {
add_filter( 'show_admin_bar', '__return_false' );
add_action( 'admin_print_scripts-profile.php',
'yoast_hide_admin_bar_settings' );
}
add_action( 'init', 'yoast_disable_admin_bar' , 9 );
Thanks to Yoast (http://yoast.com/disable-wp-admin-bar/)
Just this alone in the functions.php works for me.
// Remove Admin Bar Front End
add_filter('show_admin_bar', '__return_false');
For wordpress 3.4.2, none of these workarounds should work. I have sorted out a very simple trick to hide the admin bar!
Just after you call the wp_head(), place this style declaration:
<style>
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>
It involves no modification to the functions or whatever. Just plain old css!!
I hope it solves the Googler's problem in near future :-)
Put this in your functions.php:
/* Disable WordPress Admin Bar for all users but admins. */
if(!current_user_can("manage_options")){
show_admin_bar(false);
}
You can do this by plugin, link below:
http://wordpress.org/plugins/global-admin-bar-hide-or-remove/

WordPress Menu highlight with pagination

I have a WordPress website with a menu similar to this one: Yahoo news, so basically:
a horizontal menu with two levels, the first with main categories the second with sub-categories (in the "Home" menu item, the subcategory is the page "about us".
I am using the build-in Menu of WordPress
The problem I have is with the pagination and also with the search form:
When I am in the Home Page and I
click any pagination number, the
subcategories of "Home" menu item
disappears, and most importantly,
the "Home" menu item is no longer highlighted.
When I search something, again the
same issue, the "Home" is no
longer highlighted, and there is
no subcategory under "Home" menu
item.
I have found a solution:
1) Open header.php, and add this in the body tag:
<body<?php if ( is_home() || is_search() || is_404() ) { echo ' class="main"';} else { echo '';} ?>>
2) Add a class that target the home class, so:
body.main #main-menu ul li.menu-item-home a {
background: #313B47;
color: white;
}
Now if I am in the home page, or in the search page, or 404 error page, WordPress adds class="main" to the body, so I can easily target the menu item which I want.

Resources