picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

Best way to add script inside <head> #689

Closed digitalinferno closed 4 months ago

digitalinferno commented 5 months ago

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);         

}
PhrozenByte commented 5 months ago

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

digitalinferno commented 5 months ago

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...

PhrozenByte commented 5 months ago

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.

github-actions[bot] commented 4 months ago

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! :+1: