Archived topic
Filter to control WordPress blog post embed CSS?
5 replies · Started by Teresa on September 2, 2021
The default styling for embedded WordPress posts looks bad with my client's dark mode site. I would like to return control over the embed's background and text colors to the theme styles we have set up.
We are only wanting to control the styles for WordPress blog post embeds. Right now (and probably forever) the client only wants to embed his own posts from the same site/domain.
I understand that normally it's not possible to affect anything inside an iframe. However in the case of an embedded WordPress blog post, WordPress only fetches the post's content. Not styles. And then it adds in its own styles via one or more WordPress core files. None of which come from the original post or the theme.
I know it's possible to edit these files. I also know that for so many reasons, it's really dumb to edit core files. For fewer but still very valid reasons, it's a bad idea to copy core files like this into my theme files, even if it's a child theme. You never know when the WP team will significantly alter the way a given thing is done.
So, is there a filter I can set up that would allow me to use our theme styles? Or add my own styles? I can write any necessary CSS, but don't know much about PHP or WP filters.
Hi Teresa,
Unfortunately this isn't something the theme controls and I'm not aware of a solution.
I'd recommend checking with the WordPress support team to see if they can point you in the right direction.
Thanks for your understanding :)
Thanks for your response, Leo. It's definitely not in the theme, but I thought maybe filters would work since they do all kinds of magical things. It was worth a shot :)
I would think WordPress has some sort of embed style sheet that needs to be overwritten in order to achieve this.
Worth checking with WP support team for sure :)
This is close. It is in a php script in wp-includes. There is a function that adds the styles in a style tag that's inserted into the iframe content. If I wanted a quick fix (but not a smart one) I could edit that file.
The client agrees the post embed feature isn't a big enough deal to merit spending additional time and possibly budget on, so we're not going to dig any deeper into it.
Hi there,
not 100% sure this is relevant - but i found this hook for the embed.php:
https://developer.wordpress.org/reference/hooks/enqueue_embed_scripts/
Seen here in the core embed.php
Which means you could enqueue your own scripts, which lead me to this:
https://generatewp.com/enqueue-scripts-styles-embed-pages/
Might be completely missing something but its worth a shot :)
Oh and for reference the core filters can all be found here: