Quantcast
Channel: Topic Tag: plugin | WordPress.org
Viewing all articles
Browse latest Browse all 26892

Josh (WP Edit) on "Do theme defined custom styles added to formats dropdown override/supercede?"

$
0
0

Excellent. Glad to help.
"Norm" will be most grateful as well ;)

Interesting still, though, that the first code works in a plugin but not in a theme. Not sure if that is intended by WP or what!

Yeah, I have no idea what is going on there. I've never written a theme before; so I don't have much to compare :)

This is a quote from "Otto":

No, the theme's functions.php file is called well after plugins are loaded.

So perhaps WP Edit was loading it's custom styles... and then your theme was loading it's custom styles. With your code above... you are not first checking to see if any custom styles exist. You're simply writing a new set.. and running with that.

Perhaps something like this would work in your theme:

if(!empty($init_array['style_formats'])) {

    $incoming_array = json_decode($init_array['style_formats'], true);
    $new_merge = json_encode(array_merge($incoming_array, $style_formats));
}
else {

    $new_merge = json_encode($style_formats);
}

$init_array['style_formats'] = $new_merge;

return $init_array;

That will first check if there are any custom styles already in the array; and if there are, it will merge them with your theme custom styles. If there are no styles in the incoming array; we simply create the theme custom styles.


Viewing all articles
Browse latest Browse all 26892

Trending Articles