Last active
May 12, 2022 10:23
-
-
Save keiraarts/b9c0e635ac1364fd8464e0f4e332408a to your computer and use it in GitHub Desktop.
How to solve the PHP Notice: is_page was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. By using the Template Redirect hook the action can be called before any templates are loaded.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Currently there is an issue in our PHP server error logs. | |
// PHP Notice: is_page was called incorrectly. | |
// Conditional query tags do not work before the query is run. Before then, they always return false. | |
// This is the wrong way to call is_page. | |
// is_page() only work within template files. | |
// To use it within plugin files, you need to use it with the combination of template_redirect action hook. | |
// function wordpress_theme_enqueue_styles() { | |
// if (is_page(2072)) { | |
// wp_enqueue_style('accountdetails-style', get_stylesheet_directory_uri() . '/accountdetails.css?v=5', array('parent-style')); | |
// } | |
// } | |
// This is the correct way of re-writing the function. | |
// This action hook executes just before WordPress determines which template page to load. | |
// Source: https://stackoverflow.com/questions/22070223/how-can-i-use-is-page-inside-a-plugin | |
add_action( 'template_redirect', 'footer_css' ); | |
function footer_css() { | |
if (is_page() || is_product() || is_singular('post') || is_woocommerce() || is_cart() || is_checkout()) { | |
wp_enqueue_style('Footer_Links-style', get_stylesheet_directory_uri() . '/CSS_Components/Footer_Links.css?v=2.5', array( 'parent-style')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To solve this problem, I am suppose to copy/paste this PHP file into my FTP? If so, into which folder? Do I then need to use the "embed" script? If so, where should I add that?