Claro, puedo ayudarte a segmentar el código para que sea compatible con WordPress. A continuación, dividiré el código en cuatro archivos:
- index.php: Aquí estará el contenido principal y la estructura de la plantilla de WordPress.
- style.css: Contendrá los estilos CSS.
- script.js: Contendrá el código JavaScript necesario.
- index.html: Este será el archivo resultante solo para fines de referencia, aunque en WordPress no se usa HTML puro.
1. index.php
<?php
/*
Theme Name: YouTube Thumbnail Downloader
Description: A simple theme to download YouTube video thumbnails.
Version: 1.0
Author: Your Name
*/
get_header(); ?>
<header>
<div id="logoContainer">
<img id="logo" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBysPlyhSK-c34z54Ca5GBTjjnBGQbI4_O5slFNlM_Y24nnAXBQwojevN9ScJwTklbZHlsZcMCAOFvYtMXo7YQZRAVLbzulCvWeSAQsgwgyWY5bnT6EAOGBTw3ugv7pzOleehLCZfHKL1E0LCV_0SweQrZMDnTJoHLy7cU2JNhqMbpjpzLaeslp34XlUw/s1600/Screenshot%202023-12-20%20at%205.31.38%20PM.png" alt="Youtube Thumbnail Downloader"/>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="<?php echo esc_url( home_url( '/privacy-policy' ) ); ?>">Privacy Policy</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</div>
<h1>YouTube Video Thumbnail Downloader</h1>
</header>
<div id="adSpaceTop">
<p>This is an ad space. Insert your ad code here.</p>
</div>
<p>Download YouTube and Vimeo thumbnail images for free. Just paste the URL of the thumbnail video in the below input and click Get Thumbnail Image:</p>
<input type="text" id="videoUrl" placeholder="Enter YouTube video URL"/>
<button id="showThumbnail">Show & Download Thumbnail</button>
<div id="thumbnailLinkAbove"></div>
<div id="thumbnailContainer"></div>
<div id="thumbnailLinkBelow"></div>
<div id="adSpaceMiddle">
<p>This is an ad space. Insert your ad code here.</p>
</div>
<h2>What is YouTube Thumbnail</h2>
<p>Content Content Content</p>
<div id="adSpaceBottom">
<p>This is an ad space. Insert your ad code here.</p>
</div>
<?php get_footer(); ?>
2. style.css
/*
Theme Name: YouTube Thumbnail Downloader
Theme URI: http://example.com
Author: Your Name
Author URI: http://example.com
Description: A simple theme to download YouTube video thumbnails.
Version: 1.0
License: GNU General Public License v2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
header {
text-align: center;
margin-bottom: 20px;
}
h1 {
margin-bottom: 20px;
}
nav {
margin-bottom: 20px;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
justify-content: center;
}
nav li {
margin: 0 10px;
}
nav a {
text-decoration: none;
color: #333;
font-weight: bold;
font-size: 16px;
}
#logoContainer {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 20px;
}
#logo {
max-width: 100%;
height: auto;
margin-right: 10px;
}
p {
margin-bottom: 10px;
}
input[type="text"] {
width: 100%;
padding: 10px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
}
button {
display: block;
margin: 0 auto;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
#adSpaceTop, #adSpaceMiddle, #adSpaceBottom {
text-align: center;
margin: 20px 0;
}
#thumbnailLinkAbove, #thumbnailLinkBelow {
text-align: center;
margin: 20px 0;
}
#thumbnailContainer img {
max-width: 100%;
display: block;
margin: 20px 0;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
3. script.js
document.getElementById('showThumbnail').addEventListener('click', function() {
const videoUrl = document.getElementById('videoUrl').value;
const regex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
const match = videoUrl.match(regex);
if (match) {
const videoId = match[1];
const thumbnailUrl = `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`;
const thumbnailContainer = document.getElementById('thumbnailContainer');
thumbnailContainer.innerHTML = `<img src="${thumbnailUrl}" alt="Video Thumbnail"/>`;
const thumbnailLinkAbove = document.getElementById('thumbnailLinkAbove');
const thumbnailLinkBelow = document.getElementById('thumbnailLinkBelow');
thumbnailLinkAbove.innerHTML = '';
thumbnailLinkBelow.innerHTML = '';
const anchorAbove = document.createElement('a');
anchorAbove.href = thumbnailUrl;
anchorAbove.setAttribute('download', '');
anchorAbove.textContent = 'Download Thumbnail (Above)';
thumbnailLinkAbove.appendChild(anchorAbove);
const anchorBelow = document.createElement('a');
anchorBelow.href = thumbnailUrl;
anchorBelow.setAttribute('download', '');
anchorBelow.textContent = 'Download Thumbnail (Below)';
thumbnailLinkBelow.appendChild(anchorBelow);
} else {
alert('Invalid YouTube video URL. Please enter a valid URL.');
}
});
4. index.html (para referencia)
Este archivo se puede utilizar como referencia para ver la estructura general, pero en WordPress no es necesario.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>YouTube Video Thumbnail Downloader</title>
<link rel="stylesheet" href="styles.css"/>
</head>
<body>
<!-- El contenido de index.php se refleja aquí... -->
<!-- Código HTML de index.php -->
<script src="script.js"></script>
</body>
</html>
Pasos Adicionales para WordPress
-
Estructura de Archivos: Crea una nueva carpeta dentro de la carpeta wp-content/themes/ de tu instalación de WordPress y coloca estos archivos allí:
index.php
style.css
script.js
-
Enqueue de Scripts: Deberías incluir el archivo JavaScript en functions.php para que se cargue correctamente. Crea un archivo functions.php en tu carpeta de tema con el siguiente contenido:
<?php
function enqueue_scripts() {
wp_enqueue_script('custom-script', get_template_directory_uri() . '/script.js', array(), null, true);
}
add_action('wp_enqueue_scripts', 'enqueue_scripts');
Con esta estructura, tendrás un tema de WordPress funcional que utiliza la lógica y el diseño de tu aplicación de descarga de miniaturas de YouTube. Recuerda personalizar el nombre del tema y la información del autor en el archivo style.css. ¡Hazlo y verifica que todo funcione correctamente en tu instalación de WordPress!