Generally said, there should nothing be happening before the get_header() call.
So initiate your class if is_page() is true via wp_head action hook. Example:
add_action( 'wp_head', 'initiate_my_class' );
function initiate_my_class() {
if ( is_page() ) {
//code
}
}
Edit: As @AndrewBartel in his comment said you can globalize your variable or implement some kind of storage system via the class or another one.
Related Posts:
- Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
- What process do you use for WordPress development? [closed]
- Why does WordPress use outdated jQuery v1.12.4?
- What is the advantage of using wp_mail?
- Should Plugin Folders Include a Blank index.php File?
- Should I create a theme or a plugin?
- Include third party Javascript library which is not included in WordPress
- Where do I start from
- WP 3.3 Tooltips API?
- Check for featured image in WP_Query
- wp_remote_get doesn’t work with secure connections https?
- How to Use WordPress Color Picker API in Custom Post Type Metabox
- Get file headers in custom file
- Custom theme sufficient or custom plugin neccessary for this feature set?
- How to: get main plugin/theme file?
- How to debug WordPress correctly?
- add_theme_support using a plugin
- What is the difference between these two methods of writing $ instead of jQuery in WordPress [closed]
- Whats the difference between blog_info(‘stylesheet_url’) difference get_stylesheet_uri()
- Paging on a future post loop?
- Is there any way to have Featured Text, as opposed to Featured Image?
- How to check if a stylesheet is already loaded?
- Find source of notice / warning / errors efficiently
- Problem with is_active_sidebar?
- StackExchange clone using WordPress?
- Sharing common functionality (functions, template parts) between plugins and themes?
- Change template dynamically
- WordPress add_admin_page not working even parameters are correct?
- Get Current Menu Location inside Nav_Walker
- Short code not working in boostrap modal dont no why?
- Is there a way to list all actions registered by a plugin or theme?
- Howto: Use Custom Post Types as Submenu Items in Admin
- Extending theme PHP class in plugin
- Elementor custom Query with ACF fields to show matching woocommerce products custom fields
- what is the difference between these phares?
- How developed with version control word press site on shared host? [closed]
- How to limit number of number of categories displayed by categories widget
- PowerPress mobile media player
- When is the proper time to minify css and js with git workflow?
- How to hide or rename “X” and “x-child” references in website source?
- Widget HTML Display Problem
- How to create a backend for a custom theme?
- wp_nonce_field displaying twice
- WP Plugin Running before jQuery
- How to only load css for used blocks on frontend
- my own SVN for a plugin/theme
- Why enqueue styles on hook?
- Getting a WordPress Debug Strategy
- PHP File_exist() not working – Checking if File Exist in WordPress Theme Directory
- Invalid hook call on save, not edit when using swiper slider
- Proper way to use useSelect
- Conditional Generation of Image Sizes using add_image_size
- modify show UI of a registered taxonomy
- Using function from enqueued .js file in theme in plugin?
- Does WordPress default CSS have Grids?
- Using HTML links within translatable string
- How to get terms for taxonomy
- How to remove/replace current page template?
- WordPress Page Reload Takes forever during theme development
- Adjust query on single
- Using password protection to load different page elements?
- Anyone using unzip_file successfully? It uploads the zip but doesn’t extract it!
- Pass custom props to
- How do I add filter with woocommerce categories?
- Can’t upload image via submitting custom post from frontend
- Need Help to make a logic for editing posts in Frontend
- How can we stop showing short code in create or edit post section
- Error Connecting to Database WHEN Installing WordPress on XAMPP [Tried All the Usual Stuff] (Pics Included)
- How can I measure CPU and RAM used by my theme or plugin
- set a custom post type to a taxonomy term programmatically in metabox
- My enqueue admin style function doesn’t work because of ?=ver
- Determine if the current page, is being edited
- Can i prevent the effect of the_title filter on the dashboard’s posts/pages titles?
- How to embed or integrated a custom WordPress Widget into the theme?
- Looping single post in a theme
- To remove rendering of menus and header, plugin or theme?
- WordPress permalink setting
- Custom theme and plugin updating
- How can I add recent posts to menu like mashable
- Is there a general way to get a themes primary colour?
- Adding class to the parent of current-post-ancestor / current-menu-parent / current-post-parent
- problem with blank page
- How to Register/Link to .js Files in WordPress Dynamicaly in Header.php
- grouping my widgets wordpress
- Create and style menu
- If I want to create new taxonomies (e.g. Project / Documents / Etc…) is it better to create them in the theme’s functions.php or within a plugin? [duplicate]
- How to add something after a function
- Best Way to Inventory the Media Library of a 200+ Multisite Installation?
- how to insert content into wp_head after loop_end
- how many rupee or dollar charge to client to make theme [closed]
- how to catch a data from a array in WordPress
- How are themes and plugins localized using the gettext GNU framework?
- How react js and other Javascript Technologies works on WordPress plugin?
- Theme, Plugin or Both?
- Is there any other ways to replicating changes on live from staging without pushing from git
- Hook a search form anywhere on the site, using a custom plugin
- Fetch Custom Woocomerce filed data and check the data avialble in Wp-user table as nicname or username using function.php
- Remove Gutenberg Buttons Block
- useBlockProps() nests wrapper with class name inside block wrapper in the editor
- User set default settings for a Block in Site Editor