[Resolved] How to display dynamic content on pages based on a selection on the landing page
This thread is resolved. Here is a description of the problem and solution.
Problem:
How to display dynamic content on pages based on a selection on the landing page
Solution:
There is no such feature available to add URL param to nav menu items. You can use the WordPress default hook "wp_get_nav_menu_items" to do any amendments with the menu item links.
Hmm strange... when I use an URL field, it doesn't work, the link gets corrupted. But when I use a single line field with an URL in it, it does work - but then I can't validate the URL on input.
I know this is out of the scope of support, but I'm hoping it's a small problem for you to fix 🙂
I've added other pages to your code to get the ID parameter on those as well (see the code below), but when I click on another page, the ID parameter gets lost... please see this screen recording to see what I mean: hidden link
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_filter( 'wp_get_nav_menu_items','func_add_kapper_id_to_menu', 20, 3 );
function func_add_kapper_id_to_menu( $items, $menu, $args ) {
global $post;
if( is_admin() )
return $items;
if($post->post_type=="kapper"){
foreach( $items as $item )
{
if( 'Contact' == $item->title){
$item->url = $item->url.'?contact_id='.$post->ID;
$items[] = $item;
}
if( 'Wie ben ik' == $item->title){
$item->url = $item->url.'?contact_id='.$post->ID;
$items[] = $item;
}
if( 'Prijslijst' == $item->title){
$item->url = $item->url.'?contact_id='.$post->ID;
$items[] = $item;
}
}
}
return $items;
}
You need to make sure on what page/post you are and accordingly you will require to set the conditions with the above hook. I hope this helps and please kindly open a new ticket for every new question.