Image Tags

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Tags to WordPress Images</title>
</head>
<body>
<h1>Add Tags to WordPress Images</h1>
<label for="imageID">Image ID:</label>
<input type="text" id="imageID">
<br>
<label for="tags">Tags (comma-separated):</label>
<input type="text" id="tags">
<br>
<button onclick="addTagsToImage()">Add Tags</button>

<script>
function addTagsToImage() {
    const imageID = document.getElementById('imageID').value;
    const tags = document.getElementById('tags').value.split(',').map(tag => tag.trim());

    fetch('https://comicsandmemes.com/XY/wp-json/wp/v2/media/' + imageID, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer YOUR_JWT_TOKEN' // Add your authentication token here
        },
        body: JSON.stringify({
            meta: {
                wp_attachment_metadata: {
                    image_meta: {
                        keywords: tags
                    }
                }
            }
        })
    })
    .then(response => {
        if (response.ok) {
            alert('Tags added successfully!');
        } else {
            alert('Failed to add tags. Please check the image ID and try again.');
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('An error occurred. Please try again later.');
    });
}
</script>
</body>
</html>

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *