最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme customizer - modify menu item links dynamically

programmeradmin0浏览0评论

on our wordpress site we use utm_source in the querystring to determine the campaign that brought a customer to our site.

I need to dynamically add the passed utm_source from the initial page to all the menu items on the site. How can I modify all links in the wordpress menus to add the querystring variables?

on our wordpress site we use utm_source in the querystring to determine the campaign that brought a customer to our site.

I need to dynamically add the passed utm_source from the initial page to all the menu items on the site. How can I modify all links in the wordpress menus to add the querystring variables?

Share Improve this question edited Oct 19, 2020 at 17:36 afshin asked Oct 19, 2020 at 17:05 afshinafshin 1033 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 2

Can be changed using filter

add_filter('wp_get_nav_menu_items', 'add_utm_to_links', 10, 3);

function add_utm_to_links($items, $menu, $args) {

    foreach($items as $item) {
        if(!empty($item->url)) {
            $item->url .=  strchr($url, '?') === false ? '?' : '&';  
            $item->url .= 'utm=value';
        }
    }

    return $items;
}
发布评论

评论列表(0)

  1. 暂无评论