WordPress presented publish embeds in model 4.4, permitting you to simply proportion and show WordPress posts from one website online to every other. While you paste a hyperlink to a WordPress publish, it routinely seems as a styled preview with the name, excerpt, and featured picture.
Whilst this option makes sharing content material easy, the default glance would possibly now not all the time fit your site’s taste or structure, as we will be able to see beneath.

Thankfully, WordPress supplies a number of tactics to customise those embeds to raised suit your design. On this article, we’ll discover other ways to tweak and personalize WordPress publish embeds, so that they mix seamlessly together with your website online.
1. Customizing the Kinds
You’ll be able to simply alternate the embed’s look to raised fit your site’s theme by way of including a customized CSS report with the enqueue_embed_scripts
hook, which guarantees it’s loaded when the embed is displayed. You’ll be able to upload it on your theme’s purposes.php
report, for instance:
add_action( 'enqueue_embed_scripts', serve as () { wp_enqueue_style( 'my-theme-embed', get_theme_file_uri( 'embed.css' ), ['wp-embed-template'] ); } );
This serve as tells WordPress to load your customized embed.css
report when rendering an embedded publish. Now, you’ll be able to outline your personal types in css/embed.css
to switch the glance of the embed. For instance, you’ll be able to regulate the typography, colours, or structure with CSS like this:
.wp-embed { background-color: #f9f9f9; border: 1px cast #eee; border-radius: 8px; } .wp-embed-featured-image img { border-radius: 5px; }
With those adjustments, your WordPress publish embeds could have a novel taste that aligns together with your website online’s design, as proven beneath:

2. Customizing the Symbol
By way of default, WordPress publish embeds use a predefined picture measurement for the featured picture. Then again, you’ll be able to customise this to raised fit your design by way of specifying a distinct picture measurement.
For instance, if you wish to have the embed picture to be a really perfect sq. however don’t have a sq. picture measurement arrange but, you’ll be able to outline one the use of the next code on your theme’s purposes.php
report. This code will create a brand new picture measurement referred to as embed-square
, which vegetation pictures exactly to 300×300 pixels.
add_action( 'after_setup_theme', serve as () { add_image_size( 'embed-square', 300, 300, true ); } );
Then, use the embed_thumbnail_image_size
hook
add_filter( 'embed_thumbnail_image_size', serve as () { go back 'embed-square'; } );
Should you’ve already uploaded pictures sooner than including this code, WordPress received’t routinely generate the brand new embed-square
measurement for them. To mend this, you’ll be able to use the Regenerate Thumbnails plugin. This guarantees that all of your older featured pictures are to be had within the new measurement and show appropriately in publish embeds.
Now, your WordPress publish embeds will now use the embed-square
picture measurement, as proven beneath:

3. Customizing the Excerpt
The publish embeds additionally show an excerpt of the publish content material. Then again, the default duration would possibly not all the time suit your design or clarity personal tastes. Thankfully, you’ll be able to keep watch over how a lot textual content is proven by way of adjusting the excerpt duration by way of the use of the excerpt_length
For instance, if you wish to shorten the excerpt to 18 phrases particularly for embeds, you’ll be able to use the next code on your theme’s purposes.php
report:
add_filter( 'excerpt_length', serve as ($duration) { go back is_embed() ? 18 : $duration; } );
This code tests if the content material is being displayed in an embed and, if this is the case, limits the excerpt to 18 phrases. In a different way, it helps to keep the default excerpt duration, as proven beneath.

Experiment with other phrase counts to seek out the appropriate steadiness on your content material.
4. Including Customized Content material
By way of default, WordPress publish embeds show elementary knowledge just like the name, excerpt, and featured picture. Then again, chances are you’ll need to come with further main points, such because the publish’s up to date date, to supply extra context.
To take action, you’ll be able to use the embed_content
. In our case, we will be able to upload the next code within the purposes.php
report to show the publish’s up to date date:
add_action( 'embed_content', serve as () { if ( ! is_single() ) { go back; } $updated_time = get_the_modified_time( 'U' ); $published_time = get_the_time( 'U' ); if ( $updated_time > $published_time ) { $time = sprintf( '', esc_attr( get_the_modified_date( 'Y-m-d' ) ), esc_html( get_the_modified_date() ) ); printf( '', sprintf( esc_html__( 'Up to date on %s', 'devblog' ), $time ) ); } } );
Now, the publish embeds will show the up to date date after the content material, as proven beneath:

Exhibiting the up to date date is beneficial for readers to grasp if the content material has been just lately refreshed. That is particularly helpful for articles with time-sensitive knowledge, tutorials, or information posts that can alternate over the years.
5. Overriding Embed Templates
By way of default, WordPress makes use of a unmarried template report referred to as embed.php
to show embedded content material for all publish sorts, together with weblog posts, pages, and customized publish sorts. If you wish to alternate how embedded content material appears throughout your website online, you’ll be able to create a customized embed.php
report within your theme folder.
Moreover, WordPress means that you can customise embeds for particular publish sorts. For instance, when you’ve got a customized publish kind referred to as “product” and need its embed to turn additional main points like worth and availability with out affecting different embeds you’ll be able to create an embed-product.php
report on your theme folder and customise it as wanted.
>
Now, on every occasion a product publish is embedded, WordPress will use this template as a substitute of the default one.

Bonus:
Disable Submit Embed for Particular Submit Sorts
Whilst publish embeds are an invaluable function for sharing content material, chances are you’ll need to disable them for particular posts or publish sorts. For instance, you will have non-public content material that you just don’t need to be embedded on different websites.
To disable publish embeds for a particular publish, you’ll be able to use the embed_oembed_html
filter out to go back an empty string.
Right here’s an instance of the way you’ll be able to disable publish embeds for web page
publish kind.
add_filter( 'embed_oembed_html', serve as ( $html, $url, $attr, $post_id ) { if ( get_post_type( $post_id ) === 'web page' ) { go back ''; } go back $html; }, 10, 4 );
Wrapping up
WordPress publish embeds make it simple to proportion content material between internet sites. On this article, we explored a number of tactics to customise how those embeds glance, so that they fit your website online’s design and come with additional main points in your readers. Now, you’ll be able to check out those ways to create embeds that glance higher and make your content material extra attractive.
The publish 5 Tactics to Customise Your WordPress Submit Embeds gave the impression first on Hongkiat.
WordPress Website Development Source: https://www.hongkiat.com/blog/customize-wordpress-post-embeds/