Giter Site home page Giter Site logo

headless-wp-theme's Introduction

Headless WordPress Theme

Created by Casper Panduro aka Code by Panduro Best Headless WP Theme

Table of Contents

  1. Getting Started
  2. Theme Setup
  3. Custom Post Types
  4. Custom REST API Endpoints
  5. Contributing

Getting Started

  1. Install dependencies: composer install
  2. Setup frontend url in wp-config.php as define('WP_FRONTEND_URL', 'http://localhost:3000');. Default is http://localhost:3000.

Before you get started, make sure to include the necessary files at the beginning of functions.php:

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/app/theme.php';

Theme Setup

To set up your theme, the functions.php file utilizes the after_setup_theme action. It initiates the theme setup and performs specific tasks like removing user roles and adding menus.

add_action('after_setup_theme', function() {
    theme()
        ->headlessSetup()
        ->removeUserRoles(['subscriber', 'contributor', 'author', 'editor'])
        ->addMenu('main', 'Main Menu');
});

To add your own custom functions, extend the file located at /app/CodeByPanduro/Theme/Setup.php.

Custom Post Types

The init action helps you to register new custom post types.

add_action('init', function() {
    post_type()
        ->add('book')
        ->register();
});

You can add your own custom post types here.

Custom REST API Endpoints

Custom REST API endpoints can be registered using the rest_api_init action.

add_action('rest_api_init', function () {
    rest_api()->menu();
});

Contributing

For contributing to this functions.php, please ensure to follow the coding standards and guidelines outlined for the project.

headless-wp-theme's People

Contributors

casperpanduro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.