Jomatter

How to Integrate a WordPress Blog Into an HTML Website

You can integrate a WordPress blog into an existing HTML website without rebuilding the entire website in WordPress. The correct method depends on whether WordPress should directly serve the blog pages or act only as the content management system for your existing HTML frontend.

For a separate HTML frontend, the WordPress REST API is the most direct method. WordPress exposes posts as JSON through /wp-json/wp/v2/posts, so JavaScript can request blog posts, read their titles, excerpts, dates, links, and related data, and then display them inside your existing HTML design. WordPress officially documents this posts endpoint and its query parameters.

1. Choose the Integration Structure

There are two practical setups.

WordPress at /blog/: Your main pages remain HTML, while WordPress handles example.com/blog/. This is the simpler option when you want the blog to live on the same domain and do not need a completely custom blog frontend.

WordPress as a content source: WordPress runs at a URL such as blog.example.com, while your existing HTML website remains the frontend. JavaScript calls the WordPress REST API and creates the blog listing inside the HTML site.

Use the second approach when you specifically want WordPress to manage content while keeping the existing HTML design.

2. Check the WordPress REST API

Open this URL:

https://example.com/wp-json/wp/v2/posts

Replace example.com with your WordPress URL.

A working response returns JSON containing WordPress posts. The API also supports parameters such as page, per_page, search, before, and after. The default per_page value is 10, and the documented maximum is 100.

For example:

https://example.com/wp-json/wp/v2/posts?per_page=6

This requests up to six posts.

3. Create a Blog Section in Your HTML

Add a container where the posts should appear:

<section class="blog-section">
  <h2>Latest Articles</h2>
  <div id="wordpress-posts"></div>
</section>

Your existing CSS can style this section. WordPress does not need to control the appearance.

4. Fetch WordPress Posts With JavaScript

Use the browser’s fetch() API to request the posts:

<script>
const apiUrl =
  "https://example.com/wp-json/wp/v2/posts?_embed&per_page=6";

async function loadWordPressPosts() {
  const container = document.getElementById("wordpress-posts");

  try {
    const response = await fetch(apiUrl);

    if (!response.ok) {
      throw new Error(`HTTP error: ${response.status}`);
    }

    const posts = await response.json();

    posts.forEach(post => {
      const article = document.createElement("article");

      const title = document.createElement("h3");
      const link = document.createElement("a");

      link.href = post.link;
      link.textContent = post.title.rendered;
      title.appendChild(link);

      const excerpt = document.createElement("div");
      excerpt.innerHTML = post.excerpt.rendered;

      article.append(title, excerpt);
      container.appendChild(article);
    });

  } catch (error) {
    container.textContent = "Unable to load blog posts.";
    console.error(error);
  }
}

loadWordPressPosts();
</script>

The REST API returns structured JSON. A post response includes fields such as the post ID, date, title, excerpt, and public URL.

Using post.link is important because it sends visitors to the original WordPress article instead of creating a second full copy of the article on the HTML site.

5. Add Featured Images

If your posts use featured images, include _embed in the request. WordPress can include embeddable related resources in the _embedded property.

A featured image can be read with:

const image =
  post._embedded?.["wp:featuredmedia"]?.[0]?.source_url;

Check that an image exists before creating the <img> element because not every post must have a featured image.

6. Use Pagination for Larger Blogs

Do not load every WordPress post on one page. Use the REST API’s pagination support:

https://example.com/wp-json/wp/v2/posts?page=2&per_page=6

WordPress supports page and per_page for paginating collections, with per_page accepting 1 through 100.

For a larger blog, add a Load More button or numbered pagination so the browser only requests the posts it needs.

7. Integrating a Separate WordPress Domain

Suppose the HTML site is:

https://www.example.com

and WordPress is:

https://blog.example.com

These are different origins, so the browser applies cross-origin rules. WordPress’s REST API supports CORS for REST API requests, and WordPress documents that public REST API endpoints can be accessed cross-origin. Server settings or plugins can still modify the headers, so a failed browser request should be checked for CORS errors.

For public blog posts, use unauthenticated GET requests. Never place WordPress admin passwords, private API credentials, or authentication secrets in frontend JavaScript.

8. Should You Use an Iframe?

You can embed a WordPress page with an iframe:

<iframe
  src="https://example.com/blog/"
  width="100%"
  height="1000"
  loading="lazy">
</iframe>

This is easy, but it is not a good choice when you want the WordPress blog to behave like a native part of the HTML website. The iframe is a separate browsing context, making responsive height, styling, navigation, and deeper frontend control harder.

For a real integration, either let WordPress directly manage /blog/ or use the REST API to bring selected WordPress content into the HTML frontend.

9. The Clean Architecture

A typical API-based setup is:

HTML website
     ↓
JavaScript
     ↓
WordPress REST API
     ↓
WordPress posts

The HTML website can show the latest posts as cards containing a title, date, excerpt, and featured image. Each card can link to the original WordPress article.

This keeps responsibilities separate: WordPress handles publishing and content management, while HTML, CSS, and JavaScript handle the frontend design.

Conclusion

To integrate a WordPress blog into an HTML website, use one of two main approaches. Put WordPress at example.com/blog/ when you want the simplest same-domain setup. Use the WordPress REST API when the existing HTML website must remain the frontend.

For a custom HTML site that needs WordPress mainly for writing and managing articles, the REST API provides a clean solution: WordPress supplies the content, JavaScript fetches it, and your existing HTML/CSS controls how the blog appears.

Also Read This Articles

How To Make More Than One Page In Html
How To Put An Image Beside Text In Html
How To Put Text Under An Image In Html
How To Write A Paragraph In Html
What Is The Purpose Of Html In Web Development
Which Of The Following Are Examples Of Html Objects
How To Convert Html To WordPress