If you know what a Style Sheet is and know that SEO rules, then you should know that the safest way to iconize a menu item or style each page/post list items with a different image/graphic/icon is by its slug, since it’s the only thing that you will ALWAYS keep the same, or search engines would lose your page’s index and value.
Some tips to save you the time with your theme development:
- This can not be achieved with WP provided template tags.
- Menu item ID# won’t get you the actual post ID#
- Menu item title is EMPTY at least you name it differently by hand.
- Page/Post ID could change by moving, re-importing and other content handling, breaking your style sheet.
- Class names are possible since WP 2.9 but they need to be added MANUALLY, and╔
- ╔menus need to be activated and theme changed for them to work.
- A new blog won’t take those menu classes from your theme.
There’s a limitation on current wordpess version that removes post-title and post-name from menu-items in database, to prevent them to be confused with the actual page. Yes, they are stored in the same table, and until all the functions are revised to be safe not to confuse nav-menu-items with posts or pages, you can’t get the name nor title nor url! Not with single wp template tags.
Although WP considers the ID of the post as the more safe and CONSTANT piece of data you can use to refer your article as, but that’s inside your WP installation, not extensible to the real world. The post or menu ID could change due to several factors like backing up your site, moving domain, replacing page, new menu items created, etc., but there’s something you will NEVER allow to change: the PERMALINK.
Consequences of changing the url of your post are so severe, that our best clients are those who let their website in hands some hacky guy who promised╩miraculous rankings on search engines and they lost 50% of value (for a company depending on 2M internet sales).
Post and Menu IDs could change, breaking the link with your Style Seet rules, and losing your custom logos.
You might want to rather pay extra your developer to keep permalinks the same, than IDs.
So now the most SAFE and CONSTANT piece of data, for you, is the permalink, not the ID. You should do ANYTHING to get it done this way, regardless of what your programmer says is safer. He works for your Google rank, not for WordPress, so listen to me, not them.
After banging my head for days trying to get a solution for this, I realized nobody does it because WordPress doesn’t provide the data (yet).
If you are a WP guru, or a coder monkey like me, check the article about this plugin’s release for the code what will allow you to hack that wp class that can’t get the title:
If you wouldn’t hack your .php files, here’s a ready-to-use plugin, soon to appear in WordPress pages.
It’s very simple, but it adds your page / post’s slug ( sanitized-name-of-your-page ╩or ╩your-manually-entered-permalink ) to the class of the li that contains it. It also takes a little bit until your SEO defines the right permalink for your posts and you will still have to re-adjust the Style Sheet after his changes (until next release when this plugin will keep track of changes) but once the permalink is defined (they should be defined before making the post live, anyway) your icon / style will remain together with your menu item, regardless of the above scenarios where your post ID could change.
Adds a pagenamed_name-of-your-page class to each menu / list item for you to style them different, working-around WP limitation on not saving page name or title or url of the related page in menu items DB rows.
Better than using IDs, since the permalink MUST stay FOREVER for Google indexing, while menu and page ID are important only inside WP database.
- Adds a pagenamed_name-of-your-page class to each menu / list item for you to style them different.
- Works for either custom menus or page listings made with the previous wp_list_pages() function.
- Extra code to remove unwanted useless classes from menus (Need plugin editing)
- It will keep track of changes made to permalink to update the stylesheet (even though is not recommended for an old page, to prevent losing indexed value in google)
- Option in admin panel to remove unwanted useless classes from menus.
Don’t forget to rate it and tell it works! 〉〉〉〉〉〉〉〉〉〉〉〉
Easy: Install and activate. No options yet (future releases will)
Check out PageNamed Menu Classes plugin page for bug reports, updates, help, and to find other interesting plugins.
Go to the Plugins section of your Dashboard, click “Add New”, make sure you are looking at the “Search” section (tab-less links above). There enter “PageNamed Menu Classes” in the search field, and click “Install Now”. (you are probably there now) After installed, Activate it, and you’re set.
If you got this by email, upload the zip to your site through the “upload” tab-less link in the “Add New” section of your “Plugins” control panel in your WP Dashboard. Then Activate.
Contributors & Developers
“PageNamed Menu Classes” is open source software. The following people have contributed to this plugin.
Interested in development?
PageNamed Menu Clases Release.