I want to add a variable in the Menu, for passing a value in all my page.
The purpose is to retrieve a value for transport to another web site (from my website links) to the tracking, this value depends on the origin of the user.
eg of my menu :
- Home = mylink/?partenaire=<?php
echo $myPartenaire;
?>
- About us = mylink/aboutus.php?partenaire=<?php
echo $myPartenaire;
?>
- Contact = mylink/contact.php?partenaire=<?php
echo $myPartenaire;
?>
I can retrieve the value in my page but not in the menu
-
I’ve installed this plugin to put PHP in my page
http://wordpress.org/extend/plugins/insert-php/ -
In function.php before “
?>
” at the bottom of the page, I’ve add :$myPartenaire = $_GET['partenaire'];
-
In header.php
At the beginning, I’ve add :<?php global $myPartenaire ; ?>
-
In my page I can retrieve the value, I’ve add :
[insert_php] global $myPartenaire ; [/insert_php] <a href="http://mylink.com/mypage.php?partenaire=[insert_php] echo $myPartenaire; [/insert_php]">LINK OF MY PAGE</a> eg : mylink/contact?partenaire=<?php echo $myPartenaire; ?>
I know after how to get the value of “partenaire” in my page, but I don’t know how to add the value
partenaire=<?php
echo $myPartenaire;
?>
in all the link in my nav menu.
You should never need a plugin to insert raw PHP code somewhere. There are always side effects you cannot see or fix easily.
Filter
wp_nav_menu_objects
instead, and add the parameter here to the URLs.See this answer on creating a custom menu Walker
https://wordpress.stackexchange.com/a/14039/6477
Then instead of adding a “description” as per the answer, you should be able to modify the href link.