I want my plugin to register the script only on a specific page.
For example, inside my plugin file I want to write something like this:
if (is_page()) {
$pageid_current = get_the_ID();
$page_slug = get_post($pageid_current)->post_name;
if ($page_slug == 'articles'){
wp_register_script('myscript', '/someurl/main.js');
}
}
But I get the error:
is_page is being called incorrectly. Conditional request tags do not work before executing the request. Before that, they always return false. please see the "Debugging in WordPress" section for more information. (This post was added in version 3.1.)
How can I register a script on a specific page inside a plugin?
source
share