When managing a website or blog, optimizing links is one of the key factors that should not be overlooked. One effective solution to address this issue is integrating the 1s.is URL shortener tool into WordPress or Blogger (Blogspot) automatically and for free. This guide will help you easily achieve that.
First, you need to contact the 1s.is admin to register for your free API by emailing: [email protected] – Once you receive the API, you just need to place the corresponding code into your website to complete the integration:
WordPress:
<div id="shortlink-display"></div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const apiKey = 'your_api_key'; // Thay thế bằng khóa API của bạn
const currentUrl = window.location.href; // Lấy URL hiện tại
const displayArea = document.getElementById('shortlink-display');
fetch('https://1s.is/wp-admin/admin-ajax.php?action=shorten_url&key=${apiKey}&url=${encodeURIComponent(currentUrl)}')
.then(response => response.json())
.then(data => {
if (data.success) {
const shortUrl = data.data.short_url;
displayArea.innerHTML = `<p>URL ngắn: <a href="${shortUrl}" target="_blank">${shortUrl}</a></p>`;
} else {
displayArea.innerHTML = 'Không thể tạo shortlink.';
}
})
.catch(error => {
console.error('Có lỗi xảy ra:', error);
displayArea.innerHTML = 'Có lỗi xảy ra khi tạo shortlink.';
});
});
</script>
Blogger (Blogspot):
<iframe id='1sIframe' style='width: 100%; height:50px; border: none;'/>
<script>
const currentUrl = window.location.href;
const encodedUrl = encodeURIComponent(currentUrl);
const newUrl = 'https://1s.is/blogger/rutgonlink.html?action=shorten_url&url=${encodedUrl}';
console.log(newUrl);
const iframe = document.getElementById('1sIframe');
iframe.src = newUrl;
</script>
One of the most common questions is: What are the benefits of using a URL shortener? First, using shortened links makes sharing much easier on social media or other platforms. Additionally, it helps you track the number of clicks on the links more effectively. This is especially important if you are running online marketing campaigns.
Automatically shortening links on Blogger and WordPress not only improves user experience but also helps you manage your links more professionally. Don’t miss this opportunity to make your blog or website more attractive with short, easy-to-remember links.
Good luck with integrating the 1s.is URL shortener tool into your WordPress and Blogger platforms!