Roots Discourse

Custom endpoint/script for theme



A (sage 9 based) theme needs to provide custom SVGs (using PHP).
Is it possible to give the theme a custom URL which can be used for generating these SVGs using PHP so the browser can use them? The SVGs can’t be inlined, they must be external. Could the WordPress ajax feature somehow (ab)used for this with a different content-type instead for JSON?


If I understand you correctly you want to generate SVG on the fly using PHP and serve them under specific URL.

My first question would be - why do you want to do it in theme?
Better place for doing it would be a small custom plugin where you just register a new rewrite rule (new URL route) and serve your script from that path.

For example using the function below
and then register something like