Skip Navigation

[Resolved] Embedding a Twitter (X) video in a post

This thread is resolved. Here is a description of the problem and solution.

Problem:

I am trying to embed a Twitter/X video into a WYSIWYG field created with Toolset, but every time I paste the embed code and update the post, the content either disappears or does not render properly on the front end.

Solution:

Add a custom PHP snippet to enqueue the Twitter widget script in the site’s header using wp_enqueue_script inside a wp_head action, ensuring Twitter embeds are loaded and displayed correctly.

Relevant Documentation:

https://toolset.com/forums/topic/whatt-the-correct-way-to-add-a-snippet-of-code-entered-via-a-toolset-field/

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 3 replies, has 1 voice.

Last updated by Djuna 1 month, 1 week ago.

Assisted by: Christopher Amirian.

Author
Posts
#2807018

Tell us what you are trying to do?

As in the example below, I've created a WYSIWIG field, then entered embed code in said field on a post. The embed code is for a Twitter/X video and oddly, everytime I paste the code in the field, then update the post, the field reverts to its content prior to the update.

Is there any documentation that you are following?

https://toolset.com/forums/topic/whatt-the-correct-way-to-add-a-snippet-of-code-entered-via-a-toolset-field/#post-2053763

Is there a similar example that we can see?

As a test, I've embedded the X video on regular WP page, without any issue.
hidden link

And in the WYSIWIG field of the CPT page where I'm trying to embed the Twitter video, I can embed a YouTube iframe with no trouble. Test result is the second video here:
hidden link

Happy to provide login details privately.

Many thanks in advance!

#2807031

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Welcome to Toolset support. Would you please use the link below to enter the dashboard of a clean installation of WordPress and Toolset:

hidden link

Would you please replicate the issue there so I can report?

Thanks.

#2807081
TwitterEmbedSandboxResults.jpg

Thanks for your speedy reply 🙂

I got farther in the sandbox than I do on my site, but I still get a blank output on the front end.

On my site, I get a failure on the post page, when the embed snippet disappears from the WYSIWIG widget upon update.

In the sandbox, entering text in the WYSIWIG block works fine, and on a content template, a Single Field block previews the proper text from Twitter. (I see the same text I see on my vanilla WP test page before the video loads.) But, alas, that preview doesn't make it to the frontend (even after vigorous cache dumps).

Sandbox Test: hidden link

Working example on WP page: hidden link

Note I've removed the WYSIWIG field from my site for now, so the link to see a YouTube embed I made in that field has expired.

#2807121

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Thank you for your reply. I created a video to show how I fixed the problem:

hidden link

The PHP code that I used in the video is:

function enqueue_twitter_widget_script_in_head() {
    wp_enqueue_script(
        'twitter-widgets',
        '<em><u>hidden link</u></em>',
        array(),
        null,
        false // 'false' loads it in the <head>, not in the footer
    );
}
add_action('wp_head', 'enqueue_twitter_widget_script_in_head');

You can check how I did that int he Sandbox installation:

hidden link

Thank you very much.

#2807158

Thank you for such a clear and speedy reply Christian!

It's working! hidden link

I wondered about that script tag...

Again, many, many thanks!!