Saturday, December 31, 2022
HomeWordPress DevelopmentHow do i set international variable in a operate in wordpress features.php

How do i set international variable in a operate in wordpress features.php


Both declare your international variable exterior of operate scope (aka, international scope), or globalize it with the international key phrase.

operate foobar() {
  international $aduration;
  $aduration = shortcode_atts($default, $atts);
  //...
}

To entry a worldwide you declared elsewhere, use the worldwide key phrase once more (globalize the variable), similar to you do with international $submit in your authentic code:

// Assuming `aduration` is asserted international elsewhere, like proven above:
<?php international $aduration; echo $aduration['link']; ?>

In brief, previous any utilization of your international variable with international $myglobal signifies that that is certainly a worldwide variable – no matter whether or not you are declaring it or accessing it. If you happen to declare it inside a operate in features.php with out the international key phrase, it is nothing extra than simply one other native variable, inside that operate.

If declared correctly as a worldwide in features.php, and need to entry it elsewhere – akin to in single.php – globalizing it successfully imports it, so php is aware of to examine the worldwide scope.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments