MYSQL add a param to disable suggested video param for the Youtube iframe

MYSQL add a param to disable suggested video param for the Youtube iframe

How To Disable Related Videos on a YouTube Embed

You can disable suggested and related videos by adding rel=0 to the HTML code. This is important for businesses and converting leads on your website.

Do this by clicking on the share button, embed, copying the code, and then pasting rel=0 after the video URL in the HTML code. When you embed that on your website it will only show videos from your channel when someone pauses the video or finishes it.

How to query add ?rel=0 in MYSQL for all src in Youtube iframe.

To modify a MySQL query to add ?rel=0 to all YouTube iframe src attributes, we'll need to use a string manipulation function. Here's a query that should accomplish this

UPDATE your_table_name
SET your_column_name = REGEXP_REPLACE(
    your_column_name,
    'src="(https?://www\\.youtube\\.com/embed/[^"]+)"',
    'src="\\1?rel=0"'
)
WHERE your_column_name LIKE '%youtube.com/embed/%'
  AND your_column_name NOT LIKE '%?rel=0%';        

This query does the following:

  1. It uses REGEXP_REPLACE to find YouTube iframe src attributes and add ?rel=0 to them.
  2. The WHERE clause ensures we only modify rows that contain YouTube embeds and don't already have ?rel=0.

You'll need to replace your_table_name and your_column_name with your actual table and column names.

A few things to note:

  1. This query assumes your YouTube iframes are using the embed URL format (youtube.com/embed/).
  2. It will only add ?rel=0 if it's not already present.
  3. If there are other query parameters already in the URL, you might need a more complex regex to append &rel=0 instead.

Tài Nguy?n

?AWS Cloud - Tymer

5 个月

Smart! SQL for bulk URL editing streamlines YouTube embed customization.

要查看或添加评论,请登录

Ngo Nguyen Cong的更多文章

社区洞察

其他会员也浏览了