Wordpress - how to get php variable on page from sidebar

I wrote my own page template for my Wordpress page, now I want to change sidebar.php to insert a small menu whenever this page template is loaded.

// sidebar.php
if ( isset($event_name) ) {
  // do something
}

But apparently sidebar.php does not recognize the $ event_name variable.

How can i solve this?

+3
source share
2 answers

While I'm not familiar with how WordPress implements templates, have you tried declaring a variable globalon the sidebar page?

+6
source
+1

Source: https://habr.com/ru/post/1731725/


All Articles