Skip Navigation

[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.

You can find the proposed solution in this case with the following reply:
- https://toolset.com/forums/topic/how-to-display-dynamic-content-on-pages-based-on-a-selection-on-the-landing-page/#post-2259333

Relevant Documentation:

This support ticket is created 2 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 19 replies, has 2 voices.

Last updated by Marcel 2 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2260963

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.

#2261065

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

When you use URL field you have to use extra attribute output='raw'.

For example:

<a href="[types field='woonplaats' output='raw' item='[wpv-search-term param='contact_id']'][/types]">Woonplaats</a>
#2261219

Yes that works, thanks!

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;
}
#2262649

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've adjusted the code I've added as given under:

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" or ($post->ID==20 and isset($_GET['contact_id'])) ){

 
    foreach( $items as $item ) 
    { 	
       if( 'Wie ben ik' == $item->title){
            
            $post_id = isset($_GET['contact_id'])?$_GET['contact_id']:$post->ID;
         
            $item->url = $item->url.'?contact_id='.$post_id;
          	$items[] = $item;
        }  
      
        if( 'Prijslijst' == $item->title){
         
              $post_id = isset($_GET['contact_id'])?$_GET['contact_id']:$post->ID;
         
            $item->url = $item->url.'?contact_id='.$post_id;
          	$items[] = $item;
        }  
      if( 'Contact' == $item->title){
         
              $post_id = isset($_GET['contact_id'])?$_GET['contact_id']:$post->ID;
         
            $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.

#2262695

That absolutely helps! Thank you so much, couldn't have done this without you 🙂