{"id":156,"date":"2018-08-23T14:16:44","date_gmt":"2018-08-23T13:16:44","guid":{"rendered":"http:\/\/codeamp.com\/?p=156"},"modified":"2024-03-03T11:56:56","modified_gmt":"2024-03-03T11:56:56","slug":"interacting-with-gutenbergs-richtext-component-using-a-button","status":"publish","type":"post","link":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/","title":{"rendered":"Interacting with Gutenberg&#8217;s RichText Component"},"content":{"rendered":"<h2>&#8230;by inserting a shortcode (using a button).<\/h2>\n<p>As of the latest WordPress update we all now know about the Gutenberg editor, and whether you love or hate it, it\u2019s here to stay.<\/p>\n<p>But, as it&#8217;s <em>so<\/em> new, it means the APIs are still being worked on &#8211; which (naturally) means some things are just not possible or documented yet.<\/p>\n<p>That being said, there are plenty of great resources out there at the moment for creating Gutenberg Blocks.&nbsp; This post assumes you know how to:<\/p>\n<ol>\n<li>Create a Gutenberg Block Plugin<br \/>\n<em>~ check out <a href=\"https:\/\/github.com\/ahmadawais\/create-guten-block\" target=\"_blank\" rel=\"noopener\">create-guten-block<\/a><\/em><\/li>\n<li>Add Toolbars to Blocks<br \/>\n<em>~&nbsp;<a href=\"https:\/\/wordpress.org\/gutenberg\/handbook\/blocks\/block-controls-toolbars-and-inspector\/\">official docs<\/a> have got you covered<\/em><\/li>\n<li>Add the RichText component to a Block<br \/>\n<em>~ check out the <a href=\"https:\/\/www.youtube.com\/watch?v=K3uQa035HTk\" target=\"_blank\" rel=\"noopener\">excellent video<\/a> by Zac Gordon<\/em><\/li>\n<\/ol>\n<h2>The Problem<\/h2>\n<p>What if we want to make a word red, or add a shortcode into our RichText Component with a single click? &#8230;and how about from a button on the toolbar?<\/p>\n<p><em>Sure, we can roll our own and create any kind of editor in our block (we have total flexibility to integrate TinyMCE however we want), but surely there&#8217;s a way to do it with the built in RichText component&#8230; After all its what the core blocks use, and we like doing things the WP way right?<\/em><\/p>\n<p>This is something that all my googling couldn&#8217;t unearth&#8230;<\/p>\n<p>After some days digging around and a lot of hacking at code I&#8217;ve found there is indeed a way.<\/p>\n<h2>The Solution<\/h2>\n<p>Before we get to that, lets get up and running with some familiar Gutenberg Block code.<\/p>\n<h3>1.&nbsp; Create a Block with RichText and BlockControls (Toolbar) Components<\/h3>\n<p>This post assumes you already know how to create a Gutenberg Block with a <code>RichText<\/code> component.&nbsp;If not, you should familiarise yourself with the resources above.&nbsp; Your code should look something like this:<\/p>\n<p><strong><a href=\"https:\/\/gist.github.com\/rmorse\/1300421889ec7fbb9217899e61ab703d\" target=\"_blank\" rel=\"noopener\">View the Code<\/a><\/strong><\/p>\n<p>Nothing out of the ordinary &#8211; we&#8217;re using <code>registerBlockType<\/code> to setup our block, adding&nbsp;<code>RichText<\/code>&nbsp;and&nbsp; <code>BlockControls<\/code>&nbsp;components to our <code>edit<\/code>&nbsp;function, with a couple of functions handling the changes and setting the content.<\/p>\n<p><em>If you&#8217;re using create-guten-block, then replace <code>src\/block\/block.js<\/code>&nbsp;with the above Gist.<\/em><\/p>\n<h3>2. Accessing the editor<\/h3>\n<h4>Using `onSetup`<\/h4>\n<p>Although it&#8217;s <a href=\"https:\/\/github.com\/WordPress\/gutenberg\/tree\/master\/packages\/editor\/src\/components\/rich-text\" target=\"_blank\" rel=\"noopener\">not documented<\/a>&nbsp;yet we can see&nbsp;<code>onSetup<\/code>&nbsp;is a <a href=\"https:\/\/github.com\/WordPress\/gutenberg\/blob\/master\/packages\/editor\/src\/components\/rich-text\/index.js#L150\" target=\"_blank\" rel=\"noopener\">callback we can utilise<\/a>&nbsp;which will return a copy of the TinyMCE editor (<code>RichText<\/code> components use TinyMCE).&nbsp; However for me at least this was not the tricky part.<\/p>\n<p><em><strong>Disclaimer: <\/strong>I&#8217;m pretty new to React + ES6 and still getting my head around some of their concepts &#8211; which is probably why I found this more difficult to understand than some might.<\/em><\/p>\n<p>My first idea was to setup a callback which receives the TinyMCE editor, and then stores a reference to that in the current object:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">function onEditorSetup( editor ) {\n    this.editor = editor;\n}<\/pre>\n<p>Fail&#8230; What&#8217;s wrong with this?&nbsp; &#8230;Scope.<\/p>\n<p>One thing I&#8217;ve learnt is, the <code>edit<\/code> function is returned for each instance of our block in the post editor view, but the parent object with the <code>edit<\/code>&nbsp;function is invoked only once when setting up the block as a block type (should be pretty obvious really, took me a minute).<\/p>\n<p>This means that anything we want to use in our <code>edit<\/code> function, must live only inside the <code>edit<\/code> function (pretty much) so that each instance is self contained, and interacts with its own objects&#8230;<\/p>\n<p>Hmm&#8230; Where to go from here&#8230; where do we store the reference to editor?<\/p>\n<h4>Extending the `edit`&nbsp;function<\/h4>\n<p>If <code>edit<\/code>&nbsp;is a function, then I could see no reliable way to keep track of each instance of our editor and controls. I did think about wrapping RichText in a React Component so I could keep a reference to the editor, within a certain scope, but then realised that I&#8217;d run in to the same problem when trying to get the toolbar button to interact with it. It was a bit beyond me.<\/p>\n<p>Cue examining the Gutenberg source code (again). Sure enough,&nbsp;<a href=\"https:\/\/github.com\/WordPress\/gutenberg\/blob\/master\/packages\/block-library\/src\/list\/index.js\" target=\"_blank\" rel=\"noopener\">there is a Gutenberg component that utilises the <code>onSetup<\/code>&nbsp;callback<\/a> and provides a great example of how to handle this scenario correctly.<\/p>\n<p>Turns out my thinking was a bit limited, what I needed to understand was that <code>edit<\/code>&nbsp;just needs to return a React Component.<\/p>\n<p>So what they&#8217;ve done with the List Component is <a href=\"https:\/\/github.com\/WordPress\/gutenberg\/blob\/master\/packages\/block-library\/src\/list\/index.js#L210\" target=\"_blank\" rel=\"noopener\">create a React Component<\/a> on <code>edit<\/code>, and return the <code>RichText<\/code> and all the trimmings together <em>within<\/em> the Component, so they can access shared local variables, functions etc.<\/p>\n<p>Great stuff, this means we can get our button talking to the editor within the same scope.<\/p>\n<p>Lets see what <code>edit<\/code> might look like, using inspiration from the Gutenberg source (check the inline comments):<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">edit: class extends Component {\n    \n    \/\/standard constructor for a component\n    constructor() {\n        super( ...arguments );\n        \n        \/\/make sure we bind `this` to the current component within our callbacks\n        this.setupEditor = this.setupEditor.bind( this );\n        this.onChangeContent = this.onChangeContent.bind( this );\n\n        this.state = {\n            \/\/we don't need our component to manage a state in this instance\n        };\n    }\n    \n    \/\/same as before, except `this` actually references this component\n    setupEditor( editor ) {\n        this.editor = editor;\n    }\n    \n    \/\/no change here again, except the binding of `this`\n    onChangeContent( newContent ) {\n        this.props.setAttributes( { content: newContent } );\n    }\n    \n    \/\/slightly different pattern of syntax here, we're returning a function\n    onClickShortcodeButton() {\n        return () =&gt; {\n            \n            \/\/the content we want to insert\n            var myContent = '[myshortcode][\/myshortcode]';\n            \n            if ( this.editor ) {\n                \/\/execCommand is a TinyMCE function\n                this.editor.execCommand( 'mceInsertContent', false, myContent );\n            }\n        };\n    }\n    \n    \/\/all react components require render - this is what will be returned by our component\n    render() {\n        const {\n            attributes,\n            setAttributes,\n            className,\n        } = this.props;\n        \n        return (\n            &lt;Fragment&gt;\n                &lt;BlockControls\n                    controls={ [\n                        {\n                            icon: 'edit',\n                            title: __( 'Insert Shortcode' ),\n                            onClick: this.onClickShortcodeButton(),\n                        },\n                    ] }\n                \/&gt;\n                &lt;RichText\n                    \/\/getSettings={ this.getEditorSettings } \/\/a useful callback for adding params to TinyMCE on setup\n                    onSetup={ this.setupEditor }\n                    key = { 'editable' }\n                    tagName = { 'p' }\n                    className = { className }\n                    onChange =  { this.onChangeContent }\n                    value = { attributes.content}\n                \/&gt;\n            &lt;\/Fragment&gt;\n        );\n    }\n},<\/pre>\n<p><em>Remember<\/em>&nbsp;<code>edit<\/code>&nbsp;<em>is now a React + ES6 Component, so the syntax is fairly standard, but not what you might be used to seeing in a Block.<\/em><\/p>\n<p>What we&#8217;ve done here is port everything (our click handlers, return elements) over so that it uses the correct syntax\/structure for a React Component.&nbsp; One thing to note is, if we&#8217;re using a React Component it must properly return the Component in the <code>render<\/code>&nbsp;method, which looks a lot like the return of our old <code>edit<\/code>&nbsp;function.<\/p>\n<p>There is one addition though, now that we have <code>this.editor<\/code>&nbsp;working within the scope of the Component, I&#8217;ve added the final functionality allowing the button to interact with it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">onClickShortcodeButton() {\n\treturn () =&gt; {\n\t\t\n\t\t\/\/the content we want to insert\n\t\tvar myContent = '[myshortcode][\/myshortcode]';\n\t\t\n\t\tif ( this.editor ) {\n\t\t\t\/\/execCommand is a TinyMCE function\n\t\t\tthis.editor.execCommand( 'mceInsertContent', false, myContent );\n\t\t}\n\t};\n}<\/pre>\n<p>This just updates the click callback to interact with <code>this.editor<\/code>, and in this case we wanted to insert a shortcode using <code>execCommand<\/code>.<\/p>\n<p><strong>And that&#8217;s it! Everything should be working together nicely now.<\/strong><\/p>\n<p>From here, the world is your oyster &#8211; you have access to the TinyMCE editor which means you can now develop the same functionality into your Gutenberg Blocks as we can with the Classic editor.<\/p>\n<p><em><strong>NB<\/strong> &#8211; you&#8217;ll notice in the source a commented <code>getSettings<\/code> callback, this allows you to modify the settings object that gets passed into TinyMCE when being initialised &#8211; might be useful!<\/em><\/p>\n<h4>Files<\/h4>\n<p><strong><a href=\"https:\/\/github.com\/rmorse\/insert-shortcode-button-guten-block\/blob\/master\/src\/block\/block.js\" target=\"_blank\" rel=\"noopener\">View the Final Code<\/a><\/strong><\/p>\n<p><strong><a href=\"https:\/\/github.com\/rmorse\/insert-shortcode-button-guten-block\" target=\"_blank\" rel=\"noopener\">Code as a CGB (create-guten-block) Plugin<\/a><\/strong><\/p>\n<h2>Conclusion<\/h2>\n<p>There are plenty of possibilities now that we&#8217;re able to access TinyMCE in our custom blocks and indeed this will be useful for many right away&#8230;<\/p>\n<p>But I&#8217;m sure there are a few others thinking, why do all this now? &#8211; what we really want to do is add this kind of functionality to the core blocks&#8230;! &#8211;&nbsp; and that&#8217;s also my thought process&#8230;<\/p>\n<p>I think in all likelihood when Gutenberg allows us to extend core blocks, they&#8217;re going to have to add a way to access the TinyMCE editors within them, much like when we use <code>onSetup<\/code>&nbsp;now within our own blocks.<\/p>\n<p>Hopefully, when the time comes and the APIs get updated, we&#8217;ll have code that&#8217;s pretty much ready to go and had some testing in the Gutenberg&nbsp; environment at least.<\/p>\n<p>That&#8217;s all for now &#8211; I would love to hear about things that you&#8217;ve made as well as any thoughts on the article.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8230;by inserting a shortcode (using a button). As of the latest WordPress update we all now know about the Gutenberg editor, and whether you love or hate it, it\u2019s here to stay. But, as it&#8217;s so new, it means the APIs are still being worked on &#8211; which (naturally) means some things are just not [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":280,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,7],"tags":[10,9,8],"class_list":["post-156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gutenberg","category-wordpress","tag-blocks","tag-richtext","tag-tinymce"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Interacting with Gutenberg&#039;s RichText Component - Code Amp<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Interacting with Gutenberg&#039;s RichText Component - Code Amp\" \/>\n<meta property=\"og:description\" content=\"&#8230;by inserting a shortcode (using a button). As of the latest WordPress update we all now know about the Gutenberg editor, and whether you love or hate it, it\u2019s here to stay. But, as it&#8217;s so new, it means the APIs are still being worked on &#8211; which (naturally) means some things are just not [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Amp\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-23T13:16:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-03T11:56:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codeamp.com\/wp-content\/uploads\/2018\/08\/gutenberg-insert-shortcode.gif\" \/>\n\t<meta property=\"og:image:width\" content=\"730\" \/>\n\t<meta property=\"og:image:height\" content=\"237\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/gif\" \/>\n<meta name=\"author\" content=\"Ross Morsali\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@rmors_\" \/>\n<meta name=\"twitter:site\" content=\"@code_amp\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ross Morsali\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/\"},\"author\":{\"name\":\"Ross Morsali\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#\\\/schema\\\/person\\\/f07e5a501a3e476f253174c4f8085e64\"},\"headline\":\"Interacting with Gutenberg&#8217;s RichText Component\",\"datePublished\":\"2018-08-23T13:16:44+00:00\",\"dateModified\":\"2024-03-03T11:56:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/\"},\"wordCount\":1139,\"publisher\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/gutenberg-insert-shortcode.gif\",\"keywords\":[\"Blocks\",\"RichText\",\"TinyMCE\"],\"articleSection\":[\"Gutenberg\",\"WordPress\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/\",\"url\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/\",\"name\":\"Interacting with Gutenberg's RichText Component - Code Amp\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/gutenberg-insert-shortcode.gif\",\"datePublished\":\"2018-08-23T13:16:44+00:00\",\"dateModified\":\"2024-03-03T11:56:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/#primaryimage\",\"url\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/gutenberg-insert-shortcode.gif\",\"contentUrl\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2018\\\/08\\\/gutenberg-insert-shortcode.gif\",\"width\":730,\"height\":237},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/interacting-with-gutenbergs-richtext-component-using-a-button\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codeamp.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Interacting with Gutenberg&#8217;s RichText Component\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#website\",\"url\":\"https:\\\/\\\/codeamp.com\\\/\",\"name\":\"Code Amp\",\"description\":\"Developing WordPress Plugins\",\"publisher\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codeamp.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#organization\",\"name\":\"Code Amp\",\"url\":\"https:\\\/\\\/codeamp.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/codeampsquare.png\",\"contentUrl\":\"https:\\\/\\\/codeamp.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/codeampsquare.png\",\"width\":500,\"height\":500,\"caption\":\"Code Amp\"},\"image\":{\"@id\":\"https:\\\/\\\/codeamp.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/code_amp\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codeamp.com\\\/#\\\/schema\\\/person\\\/f07e5a501a3e476f253174c4f8085e64\",\"name\":\"Ross Morsali\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g\",\"caption\":\"Ross Morsali\"},\"description\":\"Web developer by trade, with over 15 years building things in PHP, HTML, CSS, and JavaScript - focusing on WordPress for the last 7 years.\",\"sameAs\":[\"https:\\\/\\\/codeamp.com\",\"https:\\\/\\\/x.com\\\/rmors_\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Interacting with Gutenberg's RichText Component - Code Amp","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/","og_locale":"en_GB","og_type":"article","og_title":"Interacting with Gutenberg's RichText Component - Code Amp","og_description":"&#8230;by inserting a shortcode (using a button). As of the latest WordPress update we all now know about the Gutenberg editor, and whether you love or hate it, it\u2019s here to stay. But, as it&#8217;s so new, it means the APIs are still being worked on &#8211; which (naturally) means some things are just not [&hellip;]","og_url":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/","og_site_name":"Code Amp","article_published_time":"2018-08-23T13:16:44+00:00","article_modified_time":"2024-03-03T11:56:56+00:00","og_image":[{"width":730,"height":237,"url":"https:\/\/codeamp.com\/wp-content\/uploads\/2018\/08\/gutenberg-insert-shortcode.gif","type":"image\/gif"}],"author":"Ross Morsali","twitter_card":"summary_large_image","twitter_creator":"@rmors_","twitter_site":"@code_amp","twitter_misc":{"Written by":"Ross Morsali","Estimated reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/#article","isPartOf":{"@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/"},"author":{"name":"Ross Morsali","@id":"https:\/\/codeamp.com\/#\/schema\/person\/f07e5a501a3e476f253174c4f8085e64"},"headline":"Interacting with Gutenberg&#8217;s RichText Component","datePublished":"2018-08-23T13:16:44+00:00","dateModified":"2024-03-03T11:56:56+00:00","mainEntityOfPage":{"@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/"},"wordCount":1139,"publisher":{"@id":"https:\/\/codeamp.com\/#organization"},"image":{"@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/#primaryimage"},"thumbnailUrl":"https:\/\/codeamp.com\/wp-content\/uploads\/2018\/08\/gutenberg-insert-shortcode.gif","keywords":["Blocks","RichText","TinyMCE"],"articleSection":["Gutenberg","WordPress"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/","url":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/","name":"Interacting with Gutenberg's RichText Component - Code Amp","isPartOf":{"@id":"https:\/\/codeamp.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/#primaryimage"},"image":{"@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/#primaryimage"},"thumbnailUrl":"https:\/\/codeamp.com\/wp-content\/uploads\/2018\/08\/gutenberg-insert-shortcode.gif","datePublished":"2018-08-23T13:16:44+00:00","dateModified":"2024-03-03T11:56:56+00:00","breadcrumb":{"@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/#primaryimage","url":"https:\/\/codeamp.com\/wp-content\/uploads\/2018\/08\/gutenberg-insert-shortcode.gif","contentUrl":"https:\/\/codeamp.com\/wp-content\/uploads\/2018\/08\/gutenberg-insert-shortcode.gif","width":730,"height":237},{"@type":"BreadcrumbList","@id":"https:\/\/codeamp.com\/interacting-with-gutenbergs-richtext-component-using-a-button\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codeamp.com\/"},{"@type":"ListItem","position":2,"name":"Interacting with Gutenberg&#8217;s RichText Component"}]},{"@type":"WebSite","@id":"https:\/\/codeamp.com\/#website","url":"https:\/\/codeamp.com\/","name":"Code Amp","description":"Developing WordPress Plugins","publisher":{"@id":"https:\/\/codeamp.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codeamp.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/codeamp.com\/#organization","name":"Code Amp","url":"https:\/\/codeamp.com\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/codeamp.com\/#\/schema\/logo\/image\/","url":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/codeampsquare.png","contentUrl":"https:\/\/codeamp.com\/wp-content\/uploads\/2021\/01\/codeampsquare.png","width":500,"height":500,"caption":"Code Amp"},"image":{"@id":"https:\/\/codeamp.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/code_amp"]},{"@type":"Person","@id":"https:\/\/codeamp.com\/#\/schema\/person\/f07e5a501a3e476f253174c4f8085e64","name":"Ross Morsali","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8ba742824818fce32d5defa1b1ec3c694de80a68850ebcf041561ea3eb5985f2?s=96&d=retro&r=g","caption":"Ross Morsali"},"description":"Web developer by trade, with over 15 years building things in PHP, HTML, CSS, and JavaScript - focusing on WordPress for the last 7 years.","sameAs":["https:\/\/codeamp.com","https:\/\/x.com\/rmors_"]}]}},"_links":{"self":[{"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":0,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/media\/280"}],"wp:attachment":[{"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeamp.com\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}