Avoid global variables, they could be overwritten by other code. You could use a helper function with a static internal variable instead. Sample code:
function wpse_69365_var_storage( $var = NULL )
{
static $internal;
if ( NULL !== $var )
{
$internal = $var;
}
return $internal;
}
// first call:
wpse_69365_var_storage( 4 );
// later call:
echo wpse_69365_var_storage(); // print 4
Related Posts:
- How to add custom css file in theme?
- CSS not updating in browser when I change it
- Is wp_is_mobile() effective?
- Display Menu Name using wp_nav_menu
- What questions do you ask when asked to give an estimate on theme development?
- How to remove dashicons.min.css from frontend?
- What’s the difference between home.php and index.php?
- get_template_part vs action hooks in themes
- Get url of thumbnail from the media uploader
- Adding items to page template dropdown on Page Edit Screen
- How to use logout function on custom menu link?
- Google Maps not displaying in wordpress using Google Maps Javascript API
- Hide certain pages / posts on wp-admin, show custom filter
- What is the purpose of an extra file for translation?
- use add_action(‘wp_head’) in a widget for generating dynamic CSS styles
- Problem with registering menus – What to do when other solutions aren’t working?
- Front End Post Submit Form
- add_theme_support(‘my-custom-feature’)
- Get background color for Live Preview with Theme Customization API?
- Call to undefined function get_current_screen() on my localhost
- Cache Busting using htaccess Rewrite rule?
- Writing Clean WooCommerce Styles
- How to add oEmbed support to my theme?
- WordPress Multisite: Have the same header and footer of main-blog on all sub-blogs
- Custom header images won’t appear when set to random
- Modify Javascript Configuration Options for Theme Customizer Colour Picker
- retrofiting old blog
- Difference between is_page and is_page_template
- How to Globally Use wp_localize_script() Ajax URL
- add filter not working when cancatenating variables
- How to Edit the style of header title of Twenty Eleven Theme?
- Override parent theme’s include file from child theme
- WordPress Theme Development: How to redirect templates the right way?
- Creating Theme Options Page
- How can I let templates choose which stylesheets are enqueued?
- WordPress with broken paging page 3
- Location of theme options page menu icon
- WordPress add options to theme not displaying
- What is the right way to set up a one-page portfolio theme? [closed]
- Is it possible to edit the styling of the admin panel from within a custom theme?
- When trying to override plugin’s function by theme, my filter executes two times, I want it to run only a single time
- Can’t login unless twentyfifteen theme is active
- the_excerpt(); tag not working
- How to implement a $_SESSION alternative in WordPress inside a theme without a plugin?
- Storing the contents from txt file into The_Contents”
- Differences between developing custom themes for wordpress.com and wordpress.org?
- Easy to develop on a URL that is changed for production?
- How to show custom meta_key in each li of menu
- Can I add multiple arrays within add_theme_support( ‘colors’ )?
- Customizer – loading settings/controls/sections/panels based on a id/page id
- Where to place template files?
- [&hellip appearing instead of […]
- Getting author URL outside the loop
- Replace single_template filter with what for default posts?
- How to have content scroll over background
- Need help with adding templates (archives and sitemap) to WordPress child theme
- Change image size depending on page
- Is there Photo Categories?
- How to include a mu-plugin as a theme dependency?
- Why still output /wp-content/themes/twentynineteen?
- WordPress does not load page template or anything else, just empty page with header and footer
- How to use ajax in wordpress and sending the data without refreshing ?
- Adding an external link to product grid list pages for woocommerce
- add shortcode support in customizer
- How to make my themes compatible with different WordPress versions?
- add jquery file if a certain page is included
- Exclude subcategory from wp_query
- How do I get from search_theme_directories() to the $stylesheet (name) for switch_theme()
- Tabbed theme options query about add_settings_section callback function
- Archives and Categories in Custom Menu
- Custom search template is showing 404 when adding query string
- How do I restructure the comment HTML layout?
- How to render block editor in wp-admin custom pages programmatically
- Fetch data from database with dropdown selected option
- How do I keep my iframes responsive and scaled to fit their container?
- How to Show Next, Previous, and Page Numbers with wp_link_pages
- I don’t know why categories are showing below post
- Let user publish posts on community page
- How do I control the header space in non-front pages in Twenty Seventeen?
- Target second from last post in loop
- How to perform str_replace on the results of wp_list_pages
- Advantages/Disadvantages Using Theme Editor Instead of Pages
- Magnific Popup – Add Caption to Images
- Why do WordPress developers use so many opening and closing PHP tags when developing themes? [duplicate]
- How would I get this to work – send to post from thick box
- Safe way to echo wp_trim_words
- 3 x 3 grid of posts on the home page
- Show category and description
- How can I demonstrate themes well?
- How to update my own theme?
- trying to figure out how to use more that one image upload in the same section in theme customizer
- WordPress custom jquery not found
- Pass custom css class to add_menu_page
- How to using custom DB tables
- How to force unlink on attached/inserted images?
- Replacing static code in a template file with a sidebar and widgets?
- How to remove proudly created by WordPress in theme?
- How to set up a development/staging site to make major changes to the theme then update on the live site?
- What is the point of using the front-page.php template? [closed]
- My theme is full of error messages in the “Customize” screen, but nowhere else