html code of youtube video show on Wordpress Post with six video on one page and then…
- User
html code of youtube video show on Wordpress Post with six video on one page and then another six on next page with pagination and hover effect
- Assistant
Below is a complete guide and code snippet to achieve what you're asking for: embedding YouTube videos in a WordPress post, with 6 videos per "page" (using WordPress's built-in post pagination), and a hover effect on the video embeds. I'll assume you have 12 YouTube videos in total (split into two pages of 6 each). You can scale this up by adding more groups and pages.
Key Notes:
- WordPress Pagination: WordPress allows you to split a single post into multiple pages using the
<!--nextpage-->tag in the post editor (in the Text/HTML view, not Visual). This creates pagination links at the bottom (e.g., "1 2" or "Next Page"). - Video Embedding: I'm using responsive YouTube iframes. Replace the
VIDEO_IDplaceholders (e.g.,dQw4w9WgXcQ) with your actual YouTube video IDs. - Layout: Videos are arranged in a 3-column grid (2 rows per page) using simple CSS for responsiveness. This works well on desktop and mobile.
- Hover Effect: On hover, the video iframe scales up slightly (1.05x) with a subtle shadow for a nice effect. This is done with CSS.
- How to Implement:
- Go to your WordPress dashboard > Posts > Add New (or edit an existing post).
- Switch to the Text (HTML) editor tab.
- Paste the code below into the editor.
- Publish the post. WordPress will automatically handle the pagination.
- Customization: If your theme doesn't support grids well, consider adding a plugin like "WPBakery" or "Elementor" for better layouts. For more advanced CSS, add it to your theme's style.css or use a Custom CSS plugin.
HTML Code for the WordPress Post
Paste this directly into the Text editor of your WordPress post. It includes:
- Inline CSS for the grid and hover effect (wrapped in
<style>tags). - 12 YouTube embeds (6 per page).
<!--nextpage-->to split into pages.
<style> /* Grid Container for Videos */ .video-grid { display: grid; grid-template-columns: repeat(3, 1fr); /* 3 videos per row */ gap: 20px; /* Space between videos */ margin-bottom: 30px; } /* Responsive Video Wrapper */ .video-wrapper { position: relative; padding-bottom: 56.25%; /* 16:9 aspect ratio for YouTube */ height: 0; overflow: hidden; transition: transform 0.3s ease, box-shadow 0.3s ease; /* For hover animation */ } .video-wrapper iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } /* Hover Effect */ .video-wrapper:hover { transform: scale(1.05); /* Slight zoom on hover */ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Subtle shadow */ } /* Responsive adjustments for mobile */ @media (max-width: 768px) { .video-grid { grid-template-columns: repeat(1, 1fr); /* 1 video per row on small screens */ } } </style> <h2>Page 1: First 6 YouTube Videos</h2> <div class="video-grid"> <!-- Video 1 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 2 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_2" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 3 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_3" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 4 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_4" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 5 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_5" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 6 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_6" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> </div> <!--nextpage--> <h2>Page 2: Next 6 YouTube Videos</h2> <div class="video-grid"> <!-- Video 7 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_7" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 8 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_8" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 9 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_9" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 10 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_10" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 11 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_11" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> <!-- Video 12 --> <div class="video-wrapper"> <iframe src="https://www.youtube.com/embed/VIDEO_ID_12" frameborder="0" allowfullscreen></iframe> <!-- Replace with your VIDEO_ID --> </div> </div>How It Works:
- Pagination: The
<!--nextpage-->tag splits the post into two pages. When viewed on your site, you'll see pagination links (e.g., "1 | 2") at the bottom. Your theme controls the styling of these links—if it doesn't show them, you may need to addwp_link_pages()to your theme's single.php file or use a plugin like "Page Links To". - Grid Layout: Videos are in a responsive grid (3 per row on desktop, 1 per row on mobile).
- Hover Effect: When you hover over a video, it zooms slightly and adds a shadow. This is pure CSS and works in modern browsers.
- Responsive Videos: The
.video-wrapperensures videos scale properly without fixed widths/heights. - Adding More Pages: If you have more than 12 videos (e.g., 18), add another group of 6 videos after another
<!--nextpage-->tag.
Troubleshooting:
- Videos Not Loading: Ensure you replace
VIDEO_IDwith actual IDs (e.g., from a URL likehttps://www.youtube.com/watch?v=dQw4w9WgXcQ, the ID isdQw4w9WgXcQ). - CSS Conflicts: If your theme overrides the styles, move the
<style>block to your theme's Custom CSS section (Appearance > Customize > Additional CSS). - Performance: Embedding many iframes can slow down the page. Consider lazy-loading with a plugin like "Lazy Load - Optimize Images".
- Privacy/Ads: YouTube embeds may include tracking. If needed, use
https://www.youtube-nocookie.com/embed/instead ofyoutube.com. - Gutenberg Editor: If using the block editor, switch to "Code Editor" mode to paste this HTML.
If you need more videos, a different layout, or adjustments (e.g., more hover effects like color changes), let me know!
- WordPress Pagination: WordPress allows you to split a single post into multiple pages using the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.