Skip to content

Instantly share code, notes, and snippets.

@EdwardBock
Last active October 1, 2021 17:32
Show Gist options
  • Save EdwardBock/394699cadfdd0b186a6734c60e139244 to your computer and use it in GitHub Desktop.
Save EdwardBock/394699cadfdd0b186a6734c60e139244 to your computer and use it in GitHub Desktop.
Add reading time field to a custom sidebar
import { registerPlugin } from "@wordpress/plugins";
import { PluginSidebarMoreMenuItem, PluginSidebar } from "@wordpress/edit-post";
import { TextControl } from "@wordpress/components";
import { useReadingTime } from "./reading-time-hooks.js";
const name = "reading-time-sidebar";
registerPlugin(
"reading-time",
{
render: ()=> {
const [value, setValue] = useReadingTime();
return <>
<PluginSidebarMoreMenuItem
target={name}
>
Reading time
</PluginSidebarMoreMenuItem>
<PluginSidebar
name={name}
title="Reading time"
>
<TextControl
label="Estimated time in minutes"
onChange={setValue}
value={value}
/>
</PluginSidebar>
</>
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment