Little help

Hi,
Can someone help me with my issues? I made my theme WP and i soft rejected because if this code (i try to load my css file php )
I have redux theme options and in this file i made css customs for theme options fields (ex in options-css.php i have more but as example $main_font = marocco_get_option(‘main_font’):wink:
with this code

function marocco_get_option_css(){
	ob_start();
	get_template_part('admin/custom/options-css');
	$output = ob_get_contents();
	ob_end_clean();
	return pt_compress_css_code($output);
}

// Theme option CSS output
	$option_css = trim(preg_replace( '/\s+/', ' ', marocco_get_option_css()));
	if(!empty($option_css)) {
		echo '<style>' . $option_css . '</style>';
	}

Share the reviewer message so we can understand more.

1 Like
  1. Scripts and styles should not be hardcoded anywhere in your theme or added any other way but with wp_enqueue_* hook, wp_add_inline_style or wp_add_inline_script

and link to this part http://prntscr.com/kucz56

Do it this way:

if(!empty($option_css)) {
    	wp_add_inline_style( 'theme-style-handle', $option_css );
}

and later hook your function to wp_enqueue_scripts :

add_action( 'wp_enqueue_scripts', 'marocco_get_option_css' );

1 Like

Thanks, is copy paste fix or just an example?

I add it copy paste and is not working, i got error

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘marocco_get_option_css’ not found or invalid function name in E:\wamp\marocco\wp-includes\class-wp-hook.php on line 286

Replace marocco_get_option_css with the one you have in your files.

Also replace theme-style-handle with your theme style.css handle name ( or any already enqueued css file )

my file is options-css.php
marocco si my theme’s name

like this?
if(!empty($options_css)) {
wp_add_inline_style( ‘options-css’, $options_css );
}
add_action( ‘wp_enqueue_scripts’, ‘marocco_get_options_css’ );

No, You have to put this code - except add_action() - inside your function marocco_get_options_css

Can you please make code just to copy paste? if you have time.

thank you

You need to learn about wp_add_inline_style Don’t copy and paste this way you will never learn.

1 Like

i know but is easy if i see corect way.

i made like this

in file options-css.php at the end of code, i add your lines

if(! empty($option_css)){
			echo '<style type="text/css">'.$option_css.'</style>';
		}

add_action( 'wp_head', 'marocco_get_option_css' );

in function file i let only

function marocco_get_option_css(){
	ob_start();
	get_template_part('admin/custom/options-css');
	$output = ob_get_contents();
	ob_end_clean();
}

but not loading css

https://codex.wordpress.org/Function_Reference/wp_add_inline_style

1 Like

Thank you. I read there but i cant make it to work.
Can you help me please?

Thanks

What i don’t understand is that i can include that file custom-options.php or i need all from this file to add as wp_add_inline_style in file function (theme-options.php)

Thanks

I’m providing paid support for these kind of issues for other authors. In case of interest, you can drop me an email and send me the theme after so I can check and fix it for you. If it’s doesn’t work, it means, there are few other things are wrong, too

With your issues i can provide paid support please patch up via email and will help out in resolving issues.