Skip to content

Instantly share code, notes, and snippets.

@nmedia82
Created October 6, 2016 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmedia82/6ce2c4a4a33422e63a8c0b11a0312f75 to your computer and use it in GitHub Desktop.
Save nmedia82/6ce2c4a4a33422e63a8c0b11a0312f75 to your computer and use it in GitHub Desktop.
How add dynamic css in WP plugin while rendering shortcode
function render_shortcode_template($atts){
extract(shortcode_atts(array(), $atts));
if($this -> get_option("_show_icons") == 'yes'){
wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');
}
wp_enqueue_style($this->plugin_meta['shortname'].'-styles', $this->plugin_meta['url'].'templates/post-frontend-style.css');
//getting dynamic css
ob_start();
$this -> load_template('dynamic-css.php');
$output_css = ob_get_contents();
ob_end_clean();
wp_add_inline_style( $this->plugin_meta['shortname'].'-styles', $output_css );
wp_add_inline_style( $this->plugin_meta['shortname'].'-styles', $this -> get_option("_custom_styles") );
if ( is_user_logged_in()) {
ob_start();
$this -> load_template('post-frontend-form.php');
$output_string = ob_get_contents();
ob_end_clean();
return $output_string;
}else{
echo '<script type="text/javascript">
window.location = "'.wp_login_url( get_permalink() ).'"
</script>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment