{"id":22352418,"url":"https://github.com/bgoonz/gatsbywordpress","last_synced_at":"2026-04-06T08:01:28.615Z","repository":{"id":199752252,"uuid":"703621900","full_name":"bgoonz/GatsbyWordpress","owner":"bgoonz","description":"A gatsby project using wordpress as a cms","archived":false,"fork":false,"pushed_at":"2023-10-12T17:40:16.000Z","size":1218,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T10:10:38.729Z","etag":null,"topics":["gatsby","reactjs","tailwindcss","wordpress"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bgoonz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-11T15:27:35.000Z","updated_at":"2023-10-12T17:36:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c35dcc3-b786-43ad-a825-fe1984f071e6","html_url":"https://github.com/bgoonz/GatsbyWordpress","commit_stats":null,"previous_names":["bgoonz/gatsbywordpress"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bgoonz/GatsbyWordpress","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgoonz%2FGatsbyWordpress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgoonz%2FGatsbyWordpress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgoonz%2FGatsbyWordpress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgoonz%2FGatsbyWordpress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bgoonz","download_url":"https://codeload.github.com/bgoonz/GatsbyWordpress/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgoonz%2FGatsbyWordpress/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31464101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"online","status_checked_at":"2026-04-06T02:00:07.287Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gatsby","reactjs","tailwindcss","wordpress"],"created_at":"2024-12-04T12:18:37.161Z","updated_at":"2026-04-06T08:01:28.598Z","avatar_url":"https://github.com/bgoonz.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gatsby (Wordpress as CMS)\n\n## Getting Started:\n\n**Setup**\n\n\u003e `npx gatsby new the-gatsby-garadge https://github.com/tomphill/gatsby-wordpress-gutenberg-starter`\n\n\u003e **Install the gatsby cli**\n\n\u003e `npm install -g gatsby-cli`\n\n**Running the dev server**\n\n\u003e `gatsby develop`\n\n#### Routes:\n\n- In `/src/pages` any file we create will automatically be a route.\n- By default our home page will be `index.js` in `/src/pages`\n\n```js\nimport * as React from \"react\";\n\nconst IndexPage = () =\u003e {\n  return (\n    \u003cmain\u003e\n      \u003ch1\u003eHome Page\u003c/h1\u003e\n    \u003c/main\u003e\n  );\n};\n\nexport default IndexPage;\n\nexport const Head = () =\u003e \u003ctitle\u003eHome Page\u003c/title\u003e;\n```\n\n- In our version the h1 will not appear as large text because of the tailwind resets.\n\n- In each of our page components we can export a Head component that will be used to set the title of the page.\n\n```js\nexport const Head = () =\u003e (\n  \u003c\u003e\n    \u003cmeta name=\"description\" content=\"This is the test page\" /\u003e\n    \u003ctitle\u003eThis is the test Page\u003c/title\u003e\n  \u003c/\u003e\n);\n```\n\n**Graphql Interface can be found at:**\n\n- [http://localhost:8000/\\_\\_\\_graphql](http://localhost:8000/___graphql)\n\n**Test Query to see we are connected to Wordpress**\n\n```graphql\nquery MyQuery {\n  allWpPage {\n    nodes {\n      title\n      blocks\n    }\n  }\n}\n```\n\n![Result of Query](./images/2023-10-11-14-01-48.png)\n\n---\n\n---\n\n## Creating Pages:\n\n\u003e In the root directory of our project we can create a `gatsby-node.js` file.\n\n- We can export a function that will create pages based on the pages in our Wordpress site.\n\n```js\nexports.createPages = async ({ actions, graphql }) =\u003e {};\n```\n\n**Basic Usage**\n\n\u003e gatsby-node.js\n\n```js\nconst path = require(\"path\");\n\nexports.createPages = async ({ actions, graphql }) =\u003e {\n  const pageTemplate = path.resolve(`./src/templates/page.js`);\n  const { createPage } = actions;\n\n  const { data } = await graphql(`\n    query AllPagesQuery {\n      allWpPage {\n        nodes {\n          blocks\n          databaseId\n          uri\n        }\n      }\n    }\n  `);\n\n  for (let i = 0; i \u003c data.allWpPage.nodes.length; i++) {\n    const page = data.allWpPage.nodes[i];\n    createPage({\n      path: page.uri,\n      component: pageTemplate,\n    });\n  }\n};\n```\n\n\u003e /templates/page.js\n\n```js\nimport React from \"react\";\nfunction page() {\n  return \u003cdiv\u003eThis is a page template\u003c/div\u003e;\n}\n\nexport default page;\n```\n\n#### Render Wordpress Blocks in Gatsby:\n\n```js\nimport React from \"react\";\nimport {\n  BlockRendererProvider,\n  BlockRenderer,\n  getStyles,\n  getClasses,\n} from \"@webdeveducation/wp-block-tools\";\n\nfunction Page(props) {\n  console.log(props);\n\n  return (\n    \u003cdiv\u003e\n      \u003cBlockRendererProvider\n        allBlocks={props.pageContext.blocks}\n        renderComponent={(block) =\u003e {\n          console.log(\"Render Component:\", block);\n\n          switch (block.name) {\n            case \"core/media-text\":\n              const content = \u003cBlockRenderer blocks={block.innerBlocks} /\u003e;\n              return (\n                \u003cdiv\n                  key={block.id}\n                  className={getClasses(block)}\n                  style={getStyles(block)}\n                \u003e\n                  {block.attributes.mediaPosition === \"right\" \u0026\u0026 (\n                    \u003cdiv\u003e{content}\u003c/div\u003e\n                  )}\n                  \u003cdiv\u003eThis will be the image\u003c/div\u003e\n                  \u003cdiv\u003e\n                    {block.attributes.mediaPosition !== \"right\" \u0026\u0026 (\n                      \u003cdiv\u003e{content}\u003c/div\u003e\n                    )}\n                  \u003c/div\u003e\n                \u003c/div\u003e\n              );\n            default:\n              return null;\n          }\n        }}\n      \u003e\u003c/BlockRendererProvider\u003e\n    \u003c/div\u003e\n  );\n}\n\nexport default Page;\n```\n\n#### Using Gatsby Image:\n\n- The gatsby image plugin expects specific data to be passed into it for it to render correctly.\n\n**Setup for gatsby image in `gatsby-node.js`**\n\n```js\nfor (let i = 0; i \u003c data.allWpPage.nodes.length; i++) {\n  const page = data.allWpPage.nodes[i];\n  let blocks = page.blocks;\n  blocks = assignIds(blocks);\n  blocks = await assignGatsbyImage({\n    blocks,\n    graphql,\n    coreMediaText: true,\n  });\n  createPage({\n    path: page.uri,\n    component: pageTemplate,\n    context: {\n      blocks: blocks,\n    },\n  });\n}\n```\n\n\u003e In `page.js`\n\n```js\n\u003cdiv\u003e\n  \u003cGatsbyImage alt=\"\" image={block.attributes.gatsbyImage} /\u003e\n\u003c/div\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgoonz%2Fgatsbywordpress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbgoonz%2Fgatsbywordpress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgoonz%2Fgatsbywordpress/lists"}