It currently outputs either red or blue to change the style sheet used in the way shown. However I would prefer to have an IF statement to control the HTML output.
I'm trying to take a string generated in a WordPress plugin file, and output the value from that string to a dynamic PHP driven CSS file.
I've tried specifying the string in the plugin, then displaying it via an echo statement, but that doesn't work at all. And I've also tried turning it into a function and displaying it that way, but still no luck
I'm assuming there is no connection between the two scripts, so a string specified in one is not read into the other. But I have no idea how to link the two together so that the string can be outputted
Is it possible to pass the string from wordpress to the CSS PHP script via the URL? e.g. within your WP code an echo "<link href=\"style.css?string={$string}\" rel=\"stylesheet\" />";. You could then easily get it via $_GET in your CSS script.
Hmm, now that I've come to try and put this into action I've stumbled across the rather obvious problem that it is completely pointless.
By including all the CSS data in the URL, each page load has to download the ENTIRE CSS file as part of the URL, which is obviously not acceptable as I may as well just use <style> tags in my HEAD instead.
So ... how would I go about passing a string which is stored in my WordPress database in my style.php CSS file? Basically I just want to output the entire string of data to the CSS file.
At the moment, my beta version of my plugin inserts the styles via <style> tags but that creates very messy HTML and means the CSS information is downloaded on every page refresh.
If you are storing your data via the WordPress "option" mechanism, then just add the following code to the top of your php file in your plugin folder to access the string you have saved in the database:
PHP Code:
<?php require('../../../wp-blog-header.php'); ?>
Don't forget to output the file as CSS, not text/HTML or the browser may not render it correctly. The following will output a CSS file which contains your blogs URL. Just replace the bloginfo with whatever code you want to display in the file.