• Resolved 3Lancer

    (@3lancer)


    Hi, could it be possible to get this plugin to run PHP to generate a CSS file?

    <?php
    	header("Content-type: text/css;");
    	$current_url = dirname(__FILE__);
    	$wp_content_pos = strpos($current_url, 'wp-content');
    	$wp_content = substr($current_url, 0, $wp_content_pos);
    	require_once($wp_content . 'wp-load.php');
    ?>
    
    <?php /* General Color */ ?>
    <?php $site_gc = ot_get_option('general_color'); ?>
    .quote-start, a:hover, .person-title, .quote-author, .service-box i, .wp-pagenavi a:hover, .wp-pagenavi span.current, .su-fancy-link:hover, ul.pf-filter li.active a, .su-tabs-nav span.su-tabs-current .su-tab-icon, .su-tabs-nav span:hover .su-tab-icon, .su-tabs .pane-wrapper .pane-title:hover .su-tab-icon, .su-tabs .pane-wrapper .pane-title.su-tabs-current .su-tab-icon, .su-spoiler-title .spoiler-button.spoiler-active, .su-spoiler-title:hover .spoiler-button, .widget_side_menu  ul li.current-menu-item a {color:<?php echo $site_gc; ?>;}
    
    (etc)

    It’s basically a custom CSS file generated by picking out settings set under the admin. Such as the theme colors, font sizes, etc. It could be generated just once and then cached for the visitors as a static, as it’s not dynamically changing all the time.

    https://wordpress.org/plugins/w3-total-cache/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Ashok

    (@bappidgreat)

    Hello 3Lancer

    How did you link to that stylesheet? Did you use usual link tag?

    <link rel="stylesheet" ......... href="/path/to/style.php" />

    How’s about printing that css in wp_footer hook? Does it cache by then?

    Have a good day!

    Cheers
    Ash

    Thread Starter 3Lancer

    (@3lancer)

    Hi Ashok,

    To answer your question, it would be like this:
    <link id="dynamic-style-css" href="/themes/dynamic-style.php" rel="stylesheet" type="text/css" media="all">

    Note: It’s called dynamic, but isn’t user set, rather admin set only (so doesn’t change and could be cached).

    I’m guessing it won’t execute the PHP code to grab the variables, before making it into the CSS file however?

    Thread Starter 3Lancer

    (@3lancer)

    Yeah, tested, it doesn’t execute the PHP so you will end up with a CSS file like:

    #primary-main-menu li
    a{color:<?php echo ot_get_option('menu_opt_link_color');?>;border-color:<?php echo ot_get_option('menu_bottom_border');?>}

    I guess I’ll just have to leave that file out?

    You could capture the generated css output e.g. via php ob_start() and ob_get_clean(), write this output via php file_put_contents() to a file /path/to/style.css and then add this file via wp_enqueue_style() in a normal wp_enqueue_scripts action. Then it should be used by W3TC like a normal css file. Make sure to trigger a cache clear if your css file content changes.

    Thread Starter 3Lancer

    (@3lancer)

    @ov3rfly – Cheers, that seems like a good solution!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP generated CSS’ is closed to new replies.