picocms/Pico

Best way to add script inside <head>

digitalinferno opened this issue · 4 comments

If I want to write a plugin that needs to integrate a script or CSS into the <head> of a page, is there any specific hook I should use? Or can I use something like:

public function onPageRendered(&$output) {

...some code...

$output = preg_replace('/\<\/head\>/', "{$mycss}\n{$myjs}\n</head>" , $output);       	

}

Just tell users to add the necessary HTML tags to the Twig templates, don't fiddle with the HTML in your plugin.

Actually, the purpose of the plugin is precisely this, so it would have little or no reason to exist. Those who want to integrate this functionality must do it independently in their own theme, right? I'm thinking of things like Google Analytics, script for code prettifier, etc. A plugin do not make sense...

Those who want to integrate this functionality must do it independently in their own theme, right? I'm thinking of things like Google Analytics, script for code prettifier, etc. A plugin do not make sense...

Correct, yes.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! 👍