Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
803 views
in Q2A Core by
How can I add content to the page header from a plugin?

I'm creating an editor plugin to Q2A, and I need to add a stylesheet to the page.
by
What kind of editor plugin are you making?
by
A plugin to support bbcode.

2 Answers

0 votes
by
 
Best answer

This has now been fixed in version 1.3.1. In your editor module's get_field(...) function, you can use this code to add a style sheet:

$qa_content['css_src'][]=$this->urltoroot.'styles.css';

This assumes that you included $this->urltoroot=$urltoroot; in your module's load_module(...) function and that your CSS is in styles.css.

Be sure to set Plugin Minimum Question2Answer Version to 1.3.1 in your qa-plugin.php file, since this method won't work in 1.3!

+1 vote
by
As far as I know you can't, but you can simply add it inline where you output the HTML for the editor, it will still work that way. Or, suggest that users add the styles to their qa-styles.css file (this will avoid adding another http request).
by
I think adding the CSS file to the header is the most organized method to solve the problem. It would make it easy to update the Q2A or the plugin.

Inline the CSS code make the plugin less modular. Add the CSS to qa-style.css forces the user to update the file after updating the Q2A.

Currently I'm using the custom header to add the CSS file. I guess I'll keep this solution if I can't change the header from the plugin. This should not be affected by updates, but it's an additional step in installation that I would like to avoid...
by
You're right that it's not currently possible to add a CSS file into the page header from an editor plugin (unlike Javascript files which can be included via $qa_content['script_src']). This is clearly an oversight (apologies) and I'll aim to fix it in 1.3.1.
...