Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I understand you have to paste the link that you're embedding without any code wrapping around it, but how do I force the embedded content to be centered? Currently, the default is aligning to the left.

I could modify the core file, but it's highly discouraged, so I'm asking to see if there's any hook or filter to get around this.

Thanks!

share|improve this question

2 Answers 2

up vote 1 down vote accepted

After some Googling, I found a solution that was originally done for a Twitter embed, but I modified it to work with all oEmbed contents. Keep in mind that for this to work on existing posts, you'll need to do an "update" for the oEmbed content to refresh from the cache.

add_filter('oembed_result','center_oembed',10,3);
function center_oembed($html, $url, $args) {
    $html = '<p style="text-align: center;">' . $html . '</p>';
    return $html;
}
share|improve this answer

Quick and dirty CSS fix I came up with for Twitter oEmbed (.entry-content is specific to the theme):

.entry-content > iframe {
    margin: 0 auto !important;
}

Seems to work, YMMV.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.