Advertisement
firoze

dynamic-css-by-vfprintf

May 15th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1.  
  2. // https://codex.wordpress.org/Plugin_API/Action_Reference/customize_register
  3. function vfprintfCustomize($arg){
  4.    
  5.     $arg -> add_section('header_id',array(
  6.         'title'=>'Header Option Firoze',
  7.         'priority'=>120
  8.     ));
  9.    
  10.     $arg -> add_setting('text_color_change',array(
  11.         'default'        => '#111',
  12.         'transport'     => 'postMessage',
  13.     ));
  14.     $arg -> add_control('text_color_change',array(
  15.         'label'      => __('Color Scheme', 'themename'),
  16.         'section'    => 'header_id',
  17.         'type'       => 'color'
  18.    
  19.     ));
  20. }
  21.  
  22. add_action('customize_register','vfprintfCustomize');
  23.  
  24.  
  25. // create style.css and generate dynamic css
  26. $color = get_theme_mod("text_color_change");
  27. $file = fopen(get_stylesheet_directory()."/dynamic.css","w");
  28. vfprintf(
  29.     $file,
  30.     "
  31.     .site_title,.site-description,body{color:%s !important;}
  32.     ",
  33.     array($color)
  34. );
  35.  
  36. function my_danamic_css(){
  37. ?>
  38.     <?php if(file_exists(get_stylesheet_directory()."/dynamic.css")):?>
  39.         <link rel="stylesheet" type="text/css" href="<?php echo get_theme_file_uri("dynamic.css");?>">
  40.     <?php endif;?>
  41. <?php
  42. }
  43. add_action("wp_head","my_danamic_css");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement