Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wordpress - how to get php variable in page from sidebar

Tags:

php

wordpress

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

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

But apparently sidebar.php doesn't recognize variable $event_name.

How do I come about solving this?

like image 468
huy Avatar asked Dec 02 '25 21:12

huy


2 Answers

While I'm not familiar with the way WordPress implements templates, have you tried declaring the variable global in the sidebar page?

like image 135
Tim Lytle Avatar answered Dec 04 '25 11:12

Tim Lytle


See: Function Reference/is page template « WordPress Codex to be able to detect page template in use.

like image 28
markratledge Avatar answered Dec 04 '25 09:12

markratledge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!