<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Food Blogger Mania &#187; HTML</title>
	<atom:link href="https://foodbloggermania.it/tag/ricette/html/feed/" rel="self" type="application/rss+xml" />
	<link>https://foodbloggermania.it</link>
	<description>Food Blogger Mania</description>
	<lastBuildDate>Sat, 02 May 2026 10:13:08 +0000</lastBuildDate>
	<language>it-IT</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-11/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-11/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>santox89</dc:creator>
				<category><![CDATA[Campania]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unlike Alpine]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-11/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-11/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-10/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-10/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>Gemma archeologa tra i fornelli.</dc:creator>
				<category><![CDATA[Toscana]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unlike Alpine]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-10/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-10/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-9/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-9/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>claudialuca90</dc:creator>
				<category><![CDATA[Sicilia]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unlike Alpine]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-9/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-9/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-8/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-8/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>BucciaDiArancia</dc:creator>
				<category><![CDATA[Piemonte]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unlike Alpine]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-8/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-8/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-7/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-7/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>Alveare Delle Delizie</dc:creator>
				<category><![CDATA[Friuli Venezia Giulia]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unlike Alpine]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-7/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-7/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-6/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-6/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>Pani cunzatu</dc:creator>
				<category><![CDATA[Sicilia]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unlike Alpine]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-6/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-6/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-5/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-5/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>Ragazze conTorte</dc:creator>
				<category><![CDATA[Lazio]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unlike Alpine]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-5/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-5/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-4/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-4/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>ricette da coinquiline</dc:creator>
				<category><![CDATA[Campania]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unlike Alpine]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-4/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-4/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-3/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-3/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>fucinaidee</dc:creator>
				<category><![CDATA[Veneto]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[Mario Santos]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-3/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-3/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-2/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-2/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>Mariapia</dc:creator>
				<category><![CDATA[Basilicata]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Query Loop]]></category>
		<category><![CDATA[Unlike Alpine]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-2/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-2/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making 43% of the Web More Dynamic with the WordPress Interactivity API</title>
		<link>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api/</link>
		<comments>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api/#comments</comments>
		<pubDate>Wed, 17 Apr 2024 12:00:00 +0000</pubDate>
		<dc:creator>Ovosodo Cook</dc:creator>
				<category><![CDATA[Emilia Romagna]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Image Block]]></category>
		<category><![CDATA[Loading React]]></category>
		<category><![CDATA[Performant Optimizing]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api/</guid>
		<description><![CDATA[Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place&#160;<a href="https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Creating rich, engaging, and interactive website experiences is a simple way to surprise, delight, and attract attention from website readers and users. Dynamic interactivity like instant search, form handling, and client-side “app-like” navigation where elements can persist across routes, all without a full page reload, can make the web a more efficient and interesting place for all.</p>
<p>But creating those experiences on WordPress hasn’t always been the easiest or most straightforward, often requiring complex JavaScript framework setup and maintenance.&nbsp;</p>
<p>Now, with the Interactivity API, WordPress developers have a standardized way for doing that, all built directly into core.&nbsp;</p>
<p>The Interactivity API started as <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/block-interactivity-experiments/">an experimental plugin in early 2022</a>, became <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">an official proposal in March 2023</a>, and was finally <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/wordpress-version/version-6-5/#bring-interactions-to-blocks-with-the-interactivity-api">merged into WordPress core with the release of WordPress 6.5 on April 2, 2024</a>. <strong>It provides an easier, standardized way for WordPress developers to create rich, interactive user experiences with their blocks on the front-end.</strong></p>
<h2>ELI5: The Interactivity API and the Image Block</h2>
<p>Several core WordPress blocks, including the Query Loop, Image, and Search blocks, have already adopted the Interactivity API. The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/image-block/">Image block</a>, in particular, is a great way to show off the Interactivity API in action.&nbsp;</p>
<p>At its core, the Image blocks allow you to add an image to a post or page. When a user clicks on an image in a post or page, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/index.php#L196">the Interactivity API launches a lightbox</a> showing a high-resolution version of the image.</p>
<p>The rendering of the Image block is handled server-side. The client-side interactivity, handling resizing and opening the lightbox, is now done with the new API that comes bundled with WordPress. You can bind the client-side interactivity simply by adding the <code>wp-on--click directive</code> to the image element, referencing the <code>showLightbox</code> action in <code>view.js</code>.</p>
<p>You might say, “But I could easily do this with some JavaScript!” With the Interactivity API, the code is compact and declarative, and you get the context (local state) to handle the lightbox, resizing, side effects, and all of the other needed work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/blob/e1842bb8dadd224ccf2e7499bcff781afb9ce499/packages/block-library/src/image/view.js#L38">here in the store object</a>.</p>
<div>
<pre>
actions: {
			showLightbox() {
				const ctx = getContext();

				// Bails out if the image has not loaded yet.
				if ( ! ctx.imageRef?.complete ) {
					return;
				}

				// Stores the positons of the scroll to fix it until the overlay is
				// closed.
				state.scrollTopReset = document.documentElement.scrollTop;
				state.scrollLeftReset = document.documentElement.scrollLeft;

				// Moves the information of the expaned image to the state.
				ctx.currentSrc = ctx.imageRef.currentSrc;
				imageRef = ctx.imageRef;
				buttonRef = ctx.buttonRef;
				state.currentImage = ctx;
				state.overlayEnabled = true;

				// Computes the styles of the overlay for the animation.
				callbacks.setOverlayStyles();
			},
...

</pre>
</div>
<p>The lower-level implementation details, like keeping the server and client side in sync, just work; developers no longer need to account for them.</p>
<p>This functionality is possible using vanilla JavaScript, by selecting the element via a query selector, reading data attributes, and manipulating the DOM. But it’s far less elegant, and up until now, there hasn’t been a standardized way in WordPress of handling interactive events like these.</p>
<p>With the Interactivity API, <strong>developers have a predictable way to provide interactivity to users on the front-end</strong>. You don’t have to worry about lower-level code for adding interactivity; it’s there in WordPress for you to start using today. Batteries <em>are</em> included.</p>
<h2>How is the Interactivity API different from Alpine, React, or Vue?</h2>
<p>Prior to merging the Interactivity API into WordPress core, developers would typically reach for a JavaScript framework to add dynamic features to the user-facing parts of their websites. This approach worked just fine, so why was there a need to standardize it?</p>
<p><strong>At its core, the Interactivity API is a lightweight JavaScript library that standardizes the way developers can build interactive HTML elements on WordPress sites.</strong></p>
<p>Mario Santos, a developer on the WordPress core team, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">wrote in the Interactivity API proposal</a> that, “With a standard, WordPress can absorb the maximum amount of complexity from the developer because it will handle most of what’s needed to create an interactive block.”</p>
<p>The team saw that the gap between what’s possible and what’s practical grew as sites became more complex. The more complex a user experience developers wanted to build, the more blocks needed to interact with each other, and the more difficult it became to build and maintain sites. Developers would spend a lot of time making sure that the client-side and server-side code played nicely together.</p>
<p>For a large open-source project with several contributors, having an agreed-upon standard and native way of providing client-side interactivity speeds up development and greatly improves the developer experience.</p>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/">Five goals shaped the core development team’s decisions</a> as they built the API:&nbsp;</p>
<ol>
<li><strong>Block-first and PHP-first: </strong>Prioritizing blocks for building sites and server side rendering for better SEO and performance. Combining the best for user and developer experience.</li>
<li><strong>Backward-compatible: </strong>Ensuring compatibility with both classic and block themes and optionally with other JavaScript frameworks, though it’s advised to use the API as the primary method. It also works with hooks and internationalization.</li>
<li><strong>Declarative and reactive: </strong>Using declarative code to define interactions, listening for changes in data, and updating only relevant parts of the DOM accordingly.</li>
<li><strong>Performant: </strong>Optimizing runtime performance to deliver a fast and lightweight user experience.</li>
<li><strong>Send less JavaScript: </strong>Reduce the overall amount of JavaScript being sent on the page by providing a common framework that blocks can reuse.&nbsp; So the more that blocks leverage the Interactivity API, the less JavaScript will be sent overall.</li>
</ol>
<p>Other goals are on the horizon, including improvements to client-side navigation, as you can <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/pull/59707">see in this PR</a>.</p>
<h3>Interactivity API vs. Alpine</h3>
<p>The Interactivity API shares a few similarities to <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://alpinejs.dev/">Alpine</a>—a lightweight JavaScript library that allows developers to build interactions into their web projects, often used in WordPress and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://laravel.com/">Laravel</a> projects.</p>
<p>Similar to Alpine, the Interactivity API uses directives directly in HTML and both play nicely with PHP. <em>Unlike</em> Alpine, the Interactivity API is designed to seamlessly integrate with WordPress <em>and</em> support server-side rendering of its directives.</p>
<p>With the interactivity API, you can easily generate the view from the server in PHP, and <em>then</em> add client-side interactivity. <strong>This results in less duplication, and its support in WordPress core will lead to less architectural decisions currently required by developers.&nbsp;</strong></p>
<p>So while Alpine and the Interactivity API share a broadly similar goal—making it easy for web developers to add interactive elements to a webpage—the Interactivity API is even more plug-and-play for WordPress developers.</p>
<h3>Interactivity API vs. React and Vue</h3>
<p>Many developers have opted for <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://react.dev/">React</a> when adding interactivity to WordPress sites because, in the modern web development stack, React is the go-to solution for declaratively handling DOM interactivity. This is familiar territory, and we’re used to using React and JSX when adding custom blocks for Gutenberg.</p>
<p>Loading React on the client side can be done, but it leaves you with many decisions: “How should I handle routing? How do I work with the context between PHP and React? What about server-side rendering?”</p>
<p>Part of the goal in developing the Interactivity API was the need to <strong>write as little as little JavaScript as possible</strong>, leaving the heavy lifting to PHP, and only shipping JavaScript when necessary.</p>
<p>The core team also saw issues with how these frameworks worked in conjunction with WordPress. Developers can use JavaScript frameworks like React and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://vuejs.org/">Vue</a> to render a block on the front-end that they server-rendered in PHP, for example, but this requires logic duplication and risks exposure to issues with WordPress hooks.</p>
<p>For these reasons, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#why-preact">among others</a>, the core team preferred <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://preactjs.com/">Preact</a>—a smaller UI framework that requires less JavaScript to download and execute without sacrificing performance. Think of it like React with fewer calories.</p>
<p>Luis Herranz, a WordPress Core contributor from Automattic, outlines more details on Alpine vs the Interactivity API’s usage of Preact with a thin layer of directives on top of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#comment-44595">in this comment on the original proposal</a>.</p>
<p><strong>Preact only loads if the page source contains an interactive block</strong>, meaning it is not loaded until it’s needed, aligning with the idea of shipping as little JavaScript as possible (and shipping <em>no</em> JavaScript as a default).</p>
<p>In the original Interactivity API proposal, you can see the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/#approaches-considered">run-down and comparison of several frameworks</a> and why Preact was chosen over the others.</p>
<h2>What does the new Interactivity API provide to WordPress developers?</h2>
<p>In addition to providing a standardized way to render interactive elements client-side, the Interactivity API also provides developers with directives and a more straightforward way of creating a store object to handle state, side effects, and actions.</p>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/"><img width="1084" height="2048" src="https://en-blog.files.wordpress.com/2024/04/wordpress-interactivity-api-standard-table.png" alt="a table showing the differences of developing interactive elements on WordPress with and without a standard" class="wp-image-60877" style="width:840px;height:auto" /></a><br />
<figcaption><em>Graphic from <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: The Interactivity API – A better developer experience in building interactive blocks on WordPress.org</a></em></figcaption>
</figure>
<h3>Directives</h3>
<p>Directives, a special set of data attributes, allow you to extend HTML markup. You can share data between the server-side-rendered blocks and the client-side, bind values, add click events, and much more. The Interactivity API reference <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">lists all the available directives</a>.</p>
<p>These directives are typically added in the block’s <code>render.php</code> file, and they support all of the WordPress APIs, including <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/actions/">actions</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/plugins/hooks/filters/">filters</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/reference/functions/translations_api/">core translation</a> APIs.&nbsp;</p>
<p>Here’s the render file of a sample block. Notice the click event (<code>data-wp-on--click="actions.toggle"</code>), and how we bind the value of the aria-expanded attributes via directives.</p>
<div>
<pre>
&lt;div
	&lt;?php echo get_block_wrapper_attributes(); ?&gt;
	data-wp-interactive=&quot;create-block&quot;
	&lt;?php echo wp_interactivity_data_wp_context( array( &#039;isOpen&#039; =&gt; false ) ); ?&gt;
	data-wp-watch=&quot;callbacks.logIsOpen&quot;
&gt;
	&lt;button
		data-wp-on--click=&quot;actions.toggle&quot;
		data-wp-bind--aria-expanded=&quot;context.isOpen&quot;
		aria-controls=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
	&gt;
		&lt;?php esc_html_e( &#039;Toggle&#039;, &#039;my-interactive-block&#039; ); ?&gt;
	&lt;/button&gt;

	&lt;p
		id=&quot;&lt;?php echo esc_attr( $unique_id ); ?&gt;&quot;
		data-wp-bind--hidden=&quot;!context.isOpen&quot;
	&gt;
		&lt;?php
			esc_html_e( &#039;My Interactive Block - hello from an interactive block!&#039;, &#039;my-interactive-block&#039; );
		?&gt;
	&lt;/p&gt;
&lt;/div&gt;

</pre>
</div>
<p>Do you need to dynamically update an element&#8217;s inner text? The Interactivity API allows you to use <code>data-wp-text</code> on an element, just like you can use v-text in Vue.</p>
<p>You can bind a value to a boolean or string using <code>wp-bind–</code> or hook up a click event by using <code>data-wp-on–click</code> on the element. This means you can write PHP and HTML and sprinkle in directives to add interactivity in a declarative way.</p>
<h3>Handling state, side effects, and actions</h3>
<p>The second stage of adding interactivity is to create a store, which is usually done in your <code>view.js</code> file. In the store, you’ll have access to the same context as in your <code>render.php</code> file.</p>
<p>In the store object, you define actions responding to user interactions. These actions can update the local context or global state, which then re-renders and updates the connected HTML element. You can also define side effects/callbacks, which are similar to actions, but they respond to state changes instead of direct user actions.</p>
<div>
<pre>
import { store, getContext } from &#039;@wordpress/interactivity&#039;;

store( &#039;create-block&#039;, {
	actions: {
		toggle: () =&gt; {
			const context = getContext();
			context.isOpen = ! context.isOpen;
		},
	},
	callbacks: {
		logIsOpen: () =&gt; {
			const { isOpen } = getContext();
			// Log the value of `isOpen` each time it changes.
			console.log( `Is open: ${ isOpen }` );
		},
	},
} );
</pre>
</div>
<h2>Try it out for yourself</h2>
<p>The Interactivity API is production-ready and already running on WordPress.com! With any WordPress.com plan, you’ll have access to the core blocks built on top of the Interactivity API.&nbsp;</p>
<p>If you want to build your own interactive blocks, you can scaffold an interactive block by running the below code in your terminal:</p>
<div>
<pre>
npx @wordpress/create-block@latest my-interactive-block --template @wordpress/create-block-interactive-template 
</pre>
</div>
<p>This will give you an example interactive block, with directives and state handling set up.&nbsp;</p>
<p>You can then play around with this locally, using <code>wp-env</code>, using a staging site, or by uploading the plugin directly to your site running <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/?ref=blog#pricing-grid">a plugin-eligible WordPress.com plan</a>.&nbsp;</p>
<p>If you want a seamless experience between your local dev setup and your WordPress.com site, try using it with <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2024/03/18/github-deployments/">our new GitHub Deployments</a> feature! Developing custom blocks is the perfect use case for this new tool.</p>
<p>The best way to learn something new is to start building. To kick things off, you may find the following resources a good starting point:</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/news/2024/04/11/a-first-look-at-the-interactivity-api/">A first look at the Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpmovies.dev/">Interactivity API WP Movies demo</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/wp-movies-demo/blob/main/README.md">demo video</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/issues/60219">Follow along with this task</a> for improvements coming to the Interactivity API</li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#list-of-directives">Block editor reference</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/">Proposal: Interactivity API</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://github.com/WordPress/gutenberg/discussions/55642">GitHub issue for showcase</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/making-43-of-the-web-more-dynamic-with-the-wordpress-interactivity-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Your Business More Accessible with New Blocks</title>
		<link>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-4/</link>
		<comments>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-4/#comments</comments>
		<pubDate>Thu, 02 Apr 2020 16:21:18 +0000</pubDate>
		<dc:creator>Pani cunzatu</dc:creator>
				<category><![CDATA[Sicilia]]></category>
		<category><![CDATA[Access Permissions]]></category>
		<category><![CDATA[Add Block]]></category>
		<category><![CDATA[Eventbrite Checkout]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Layout Elements]]></category>
		<category><![CDATA[Layout Grid]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-4/</guid>
		<description><![CDATA[From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more&#160;<a href="https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-4/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more people.</p>
<p>Our team has been hard at work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/block-editor-upgrades/">improving the block editor experience</a>. We&#8217;ve launched six new blocks that integrate WordPress.com and Jetpack-enabled sites with popular services &#8212; Eventbrite, Calendly, Pinterest, Mapbox, Google Calendar, and OpenTable &#8212; enabling you to embed rich content and provide booking and scheduling options right on your blog or website. </p>
<p>Whether you&#8217;re an online boutique, a pilates studio, an independent consultant, or a local restaurant, these blocks offer you more ways to promote your brand or business. Take a look at each block &#8212; or simply jump to a specific one below.</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#eventbrite">Eventbrite</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#calendly">Calendly</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#pinterest">Pinterest</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#map">Mapbox</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#googlecalendar">Google Calendar</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#opentable">OpenTable</a></li>
</ul>
<hr class="wp-block-separator" />
<h3>Promote online events with the Eventbrite block</h3>
<p>Looking for a way to promote an online event (like your museum&#8217;s virtual curator talk or your company&#8217;s webinar on remote work), or even an at-home livestream performance for your fans and followers? Offering key features of the popular event registration platform, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block</a> embeds events on posts and pages so your visitors can register and purchase tickets right from your site.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block-image.png?w=1024" alt="" class="wp-image-42030" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need an Eventbrite account. If you don&#8217;t have one, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/signin/">sign up at Eventbrite for free</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Eventbrite Checkout</strong> block.</li>
<li>Enter the URL of your Eventbrite event. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/support/articles/en_US/How_To/how-to-customize-your-event-url-web-address?lg=en_US">Read these steps from Eventbrite</a> if you need help.</li>
<li>Select from two options: an <strong>In-page Embed</strong> shows the event details and registration options directly on your site. The <strong>Button &amp; Modal</strong> option shows just a button; when clicked, the event details will pop up so your visitor can register.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block.gif" alt="" class="wp-image-42029" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Schedule sessions with the Calendly block</h3>
<p>Want to make it easier for people to book private meditation sessions or language lessons with you? The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block</a>, featured recently in<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/move-your-classes-online/"> our guide on moving your classes online</a>, is a handy way for your clients and students to book a session directly on your site &#8212; eliminating the time spent coordinating schedules. You can also use the Calendly block to schedule team meetings or group events.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-image.png?w=1024" alt="" class="wp-image-42033" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need a Calendly account. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://calendly.com/signup">Create one for free at Calendly</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Calendly </strong>block.</li>
<li>Enter your Calendly web address or embed code. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://help.calendly.com/hc/en-us/articles/223147027-Embed-options-overview">Follow these steps from Calendly</a> if you need help.</li>
<li>Select from two styles: the <strong>Inline</strong>&nbsp;style embeds a calendar directly onto your site; the <strong>Link&nbsp;</strong>style inserts a button that a visitor can click to open a pop-up calendar.</li>
<li>This block is currently available to sites on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/">WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-block-gif.gif" alt="" class="wp-image-42034" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Up your visual game with the Pinterest block</h3>
<p>Strong visuals help to provide inspiration, tell your stories, and sell your products and services. Pinterest is an engaging way for bloggers, influencers, and small business owners to enhance their site content and expand their following. With the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/embed-from-pinterest/">Pinterest block</a>, you can embed and share pins, boards, and profiles on your site. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/pinterest-block.png?w=1024" alt="" class="wp-image-42041" /></figure>
<p><strong>Quick-start guide: </strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Pinterest </strong>block.</li>
<li>Paste the URL of a pin, board, or profile you&#8217;d like to display and click <strong>Embed</strong>. Note that you can only embed public boards.</li>
<li><em>Pro tip:</em> in the block editor, go to <strong>Layout Elements</strong> and select <strong>Layout Grid</strong> to create a visually striking layout with pins, boards,  and profiles, as shown above.</li>
</ul>
<hr class="wp-block-separator" />
<h3>Display locations with the Map block</h3>
<p>A map on your site is a quick visual way to display a location, like your restaurant&#8217;s takeout window or the drop-off spot for donations to a local food bank. Powered by mapping platform Mapbox, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block</a> embeds a customized map on your site. Show the location of your business, a chain of boutique hotels, the meeting spots for your nonprofit&#8217;s volunteers, and more.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/map.png?w=1024" alt="" class="wp-image-42044" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Map </strong>block.</li>
<li>In the text field, type the location you want to display and select the correct location from among the results that appear.</li>
<li>Click on the red marker to edit the title and caption of the marker.</li>
<li>Explore the toolbar for block-specific settings. Add more markers, for example, by clicking the <strong>Add a marker</strong> button.</li>
<li>In the sidebar, customize your map&#8217;s appearance (including colors, height, and zoom level).</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Share your calendar with the Google Calendar block</h3>
<p>Are you an author planning a book tour (or a series of online readings)? A digital marketing consultant hosting social media workshops? A neighborhood pop-up bakery? With<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/"> the Google Calendar block</a>, you can display a calendar of upcoming events or your hours of operation.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/google-calendar.png?w=1024" alt="" class="wp-image-42049" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In Google Calendar, click the three dots next to your calendar name and select&nbsp;<strong>Settings and sharing</strong>. </li>
<li>Under <strong>Access Permissions</strong>, ensure <strong>Make available to public</strong> is checked. </li>
<li>Click on <strong>Integrate calendar</strong> on the left and copy the code under <strong>Embed code</strong>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button, search for and select the <strong>Custom HTML</strong> block, and paste the code you copied in Google Calendar.</li>
<li><strong>Publish</strong> your post or page. The next time you edit this post or page, you&#8217;ll see the code has been converted to shortcode.</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/">Google Calendar block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Streamline reservations with the OpenTable block</h3>
<p>If you&#8217;re a restaurant or cafe owner, a primary goal of your site is to increase the number of bookings. Sure, people aren&#8217;t dining out right now, but you can be ready to take reservations in the future. With the&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block</a>, people can reserve a table directly from a post or page instead of calling or booking through a different reservation service. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/standard.png?w=390" alt="" class="wp-image-42057" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, your restaurant must be listed on OpenTable. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://restaurant.opentable.com/">Create an OpenTable listing now</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>OpenTable </strong>block.</li>
<li>Enter your OpenTable Reservation Widget embed code. <a target="_blank" rel="nofollow" rel="noreferrer noopener" href="/redirect.php?URL=https://support.opentable.com/s/article/How-do-I-install-the-reservation-widget-to-take-reservations-on-my-website-and-Facebook?language=en_US" target="_blank">Check this OpenTable guide</a> if you need help.</li>
<li>Explore the block&#8217;s toolbar and sidebar settings. For example, choose from four different embed styles: <strong>Standard</strong>, <strong>Tall</strong>, <strong>Wide</strong>, and <strong>Button</strong>.</li>
<li>This block is currently available to sites on the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/"> WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/opentable-block.gif?w=600" alt="" class="wp-image-42058" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block support page</a>.</em></p>
<hr class="wp-block-separator" />
<p><strong>Which blocks are you most excited about? </strong></p>
<p><strong>Stay tuned for more new blocks soon! </strong></p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Your Business More Accessible with New Blocks</title>
		<link>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-8/</link>
		<comments>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-8/#comments</comments>
		<pubDate>Thu, 02 Apr 2020 16:21:18 +0000</pubDate>
		<dc:creator>ricette da coinquiline</dc:creator>
				<category><![CDATA[Campania]]></category>
		<category><![CDATA[Access Permissions]]></category>
		<category><![CDATA[Add Block]]></category>
		<category><![CDATA[Eventbrite Checkout]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Layout Elements]]></category>
		<category><![CDATA[Layout Grid]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-8/</guid>
		<description><![CDATA[From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more&#160;<a href="https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-8/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more people.</p>
<p>Our team has been hard at work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/block-editor-upgrades/">improving the block editor experience</a>. We&#8217;ve launched six new blocks that integrate WordPress.com and Jetpack-enabled sites with popular services &#8212; Eventbrite, Calendly, Pinterest, Mapbox, Google Calendar, and OpenTable &#8212; enabling you to embed rich content and provide booking and scheduling options right on your blog or website. </p>
<p>Whether you&#8217;re an online boutique, a pilates studio, an independent consultant, or a local restaurant, these blocks offer you more ways to promote your brand or business. Take a look at each block &#8212; or simply jump to a specific one below.</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#eventbrite">Eventbrite</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#calendly">Calendly</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#pinterest">Pinterest</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#map">Mapbox</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#googlecalendar">Google Calendar</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#opentable">OpenTable</a></li>
</ul>
<hr class="wp-block-separator" />
<h3>Promote online events with the Eventbrite block</h3>
<p>Looking for a way to promote an online event (like your museum&#8217;s virtual curator talk or your company&#8217;s webinar on remote work), or even an at-home livestream performance for your fans and followers? Offering key features of the popular event registration platform, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block</a> embeds events on posts and pages so your visitors can register and purchase tickets right from your site.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block-image.png?w=1024" alt="" class="wp-image-42030" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need an Eventbrite account. If you don&#8217;t have one, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/signin/">sign up at Eventbrite for free</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Eventbrite Checkout</strong> block.</li>
<li>Enter the URL of your Eventbrite event. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/support/articles/en_US/How_To/how-to-customize-your-event-url-web-address?lg=en_US">Read these steps from Eventbrite</a> if you need help.</li>
<li>Select from two options: an <strong>In-page Embed</strong> shows the event details and registration options directly on your site. The <strong>Button &amp; Modal</strong> option shows just a button; when clicked, the event details will pop up so your visitor can register.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block.gif" alt="" class="wp-image-42029" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Schedule sessions with the Calendly block</h3>
<p>Want to make it easier for people to book private meditation sessions or language lessons with you? The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block</a>, featured recently in<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/move-your-classes-online/"> our guide on moving your classes online</a>, is a handy way for your clients and students to book a session directly on your site &#8212; eliminating the time spent coordinating schedules. You can also use the Calendly block to schedule team meetings or group events.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-image.png?w=1024" alt="" class="wp-image-42033" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need a Calendly account. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://calendly.com/signup">Create one for free at Calendly</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Calendly </strong>block.</li>
<li>Enter your Calendly web address or embed code. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://help.calendly.com/hc/en-us/articles/223147027-Embed-options-overview">Follow these steps from Calendly</a> if you need help.</li>
<li>Select from two styles: the <strong>Inline</strong>&nbsp;style embeds a calendar directly onto your site; the <strong>Link&nbsp;</strong>style inserts a button that a visitor can click to open a pop-up calendar.</li>
<li>This block is currently available to sites on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/">WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-block-gif.gif" alt="" class="wp-image-42034" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Up your visual game with the Pinterest block</h3>
<p>Strong visuals help to provide inspiration, tell your stories, and sell your products and services. Pinterest is an engaging way for bloggers, influencers, and small business owners to enhance their site content and expand their following. With the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/embed-from-pinterest/">Pinterest block</a>, you can embed and share pins, boards, and profiles on your site. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/pinterest-block.png?w=1024" alt="" class="wp-image-42041" /></figure>
<p><strong>Quick-start guide: </strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Pinterest </strong>block.</li>
<li>Paste the URL of a pin, board, or profile you&#8217;d like to display and click <strong>Embed</strong>. Note that you can only embed public boards.</li>
<li><em>Pro tip:</em> in the block editor, go to <strong>Layout Elements</strong> and select <strong>Layout Grid</strong> to create a visually striking layout with pins, boards,  and profiles, as shown above.</li>
</ul>
<hr class="wp-block-separator" />
<h3>Display locations with the Map block</h3>
<p>A map on your site is a quick visual way to display a location, like your restaurant&#8217;s takeout window or the drop-off spot for donations to a local food bank. Powered by mapping platform Mapbox, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block</a> embeds a customized map on your site. Show the location of your business, a chain of boutique hotels, the meeting spots for your nonprofit&#8217;s volunteers, and more.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/map.png?w=1024" alt="" class="wp-image-42044" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Map </strong>block.</li>
<li>In the text field, type the location you want to display and select the correct location from among the results that appear.</li>
<li>Click on the red marker to edit the title and caption of the marker.</li>
<li>Explore the toolbar for block-specific settings. Add more markers, for example, by clicking the <strong>Add a marker</strong> button.</li>
<li>In the sidebar, customize your map&#8217;s appearance (including colors, height, and zoom level).</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Share your calendar with the Google Calendar block</h3>
<p>Are you an author planning a book tour (or a series of online readings)? A digital marketing consultant hosting social media workshops? A neighborhood pop-up bakery? With<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/"> the Google Calendar block</a>, you can display a calendar of upcoming events or your hours of operation.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/google-calendar.png?w=1024" alt="" class="wp-image-42049" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In Google Calendar, click the three dots next to your calendar name and select&nbsp;<strong>Settings and sharing</strong>. </li>
<li>Under <strong>Access Permissions</strong>, ensure <strong>Make available to public</strong> is checked. </li>
<li>Click on <strong>Integrate calendar</strong> on the left and copy the code under <strong>Embed code</strong>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button, search for and select the <strong>Custom HTML</strong> block, and paste the code you copied in Google Calendar.</li>
<li><strong>Publish</strong> your post or page. The next time you edit this post or page, you&#8217;ll see the code has been converted to shortcode.</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/">Google Calendar block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Streamline reservations with the OpenTable block</h3>
<p>If you&#8217;re a restaurant or cafe owner, a primary goal of your site is to increase the number of bookings. Sure, people aren&#8217;t dining out right now, but you can be ready to take reservations in the future. With the&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block</a>, people can reserve a table directly from a post or page instead of calling or booking through a different reservation service. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/standard.png?w=390" alt="" class="wp-image-42057" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, your restaurant must be listed on OpenTable. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://restaurant.opentable.com/">Create an OpenTable listing now</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>OpenTable </strong>block.</li>
<li>Enter your OpenTable Reservation Widget embed code. <a target="_blank" rel="nofollow" rel="noreferrer noopener" href="/redirect.php?URL=https://support.opentable.com/s/article/How-do-I-install-the-reservation-widget-to-take-reservations-on-my-website-and-Facebook?language=en_US" target="_blank">Check this OpenTable guide</a> if you need help.</li>
<li>Explore the block&#8217;s toolbar and sidebar settings. For example, choose from four different embed styles: <strong>Standard</strong>, <strong>Tall</strong>, <strong>Wide</strong>, and <strong>Button</strong>.</li>
<li>This block is currently available to sites on the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/"> WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/opentable-block.gif?w=600" alt="" class="wp-image-42058" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block support page</a>.</em></p>
<hr class="wp-block-separator" />
<p><strong>Which blocks are you most excited about? </strong></p>
<p><strong>Stay tuned for more new blocks soon! </strong></p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Your Business More Accessible with New Blocks</title>
		<link>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-7/</link>
		<comments>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-7/#comments</comments>
		<pubDate>Thu, 02 Apr 2020 16:21:18 +0000</pubDate>
		<dc:creator>Alveare Delle Delizie</dc:creator>
				<category><![CDATA[Friuli Venezia Giulia]]></category>
		<category><![CDATA[Access Permissions]]></category>
		<category><![CDATA[Add Block]]></category>
		<category><![CDATA[Eventbrite Checkout]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Layout Elements]]></category>
		<category><![CDATA[Layout Grid]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-7/</guid>
		<description><![CDATA[From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more&#160;<a href="https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-7/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more people.</p>
<p>Our team has been hard at work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/block-editor-upgrades/">improving the block editor experience</a>. We&#8217;ve launched six new blocks that integrate WordPress.com and Jetpack-enabled sites with popular services &#8212; Eventbrite, Calendly, Pinterest, Mapbox, Google Calendar, and OpenTable &#8212; enabling you to embed rich content and provide booking and scheduling options right on your blog or website. </p>
<p>Whether you&#8217;re an online boutique, a pilates studio, an independent consultant, or a local restaurant, these blocks offer you more ways to promote your brand or business. Take a look at each block &#8212; or simply jump to a specific one below.</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#eventbrite">Eventbrite</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#calendly">Calendly</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#pinterest">Pinterest</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#map">Mapbox</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#googlecalendar">Google Calendar</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#opentable">OpenTable</a></li>
</ul>
<hr class="wp-block-separator" />
<h3>Promote online events with the Eventbrite block</h3>
<p>Looking for a way to promote an online event (like your museum&#8217;s virtual curator talk or your company&#8217;s webinar on remote work), or even an at-home livestream performance for your fans and followers? Offering key features of the popular event registration platform, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block</a> embeds events on posts and pages so your visitors can register and purchase tickets right from your site.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block-image.png?w=1024" alt="" class="wp-image-42030" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need an Eventbrite account. If you don&#8217;t have one, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/signin/">sign up at Eventbrite for free</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Eventbrite Checkout</strong> block.</li>
<li>Enter the URL of your Eventbrite event. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/support/articles/en_US/How_To/how-to-customize-your-event-url-web-address?lg=en_US">Read these steps from Eventbrite</a> if you need help.</li>
<li>Select from two options: an <strong>In-page Embed</strong> shows the event details and registration options directly on your site. The <strong>Button &amp; Modal</strong> option shows just a button; when clicked, the event details will pop up so your visitor can register.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block.gif" alt="" class="wp-image-42029" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Schedule sessions with the Calendly block</h3>
<p>Want to make it easier for people to book private meditation sessions or language lessons with you? The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block</a>, featured recently in<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/move-your-classes-online/"> our guide on moving your classes online</a>, is a handy way for your clients and students to book a session directly on your site &#8212; eliminating the time spent coordinating schedules. You can also use the Calendly block to schedule team meetings or group events.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-image.png?w=1024" alt="" class="wp-image-42033" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need a Calendly account. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://calendly.com/signup">Create one for free at Calendly</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Calendly </strong>block.</li>
<li>Enter your Calendly web address or embed code. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://help.calendly.com/hc/en-us/articles/223147027-Embed-options-overview">Follow these steps from Calendly</a> if you need help.</li>
<li>Select from two styles: the <strong>Inline</strong>&nbsp;style embeds a calendar directly onto your site; the <strong>Link&nbsp;</strong>style inserts a button that a visitor can click to open a pop-up calendar.</li>
<li>This block is currently available to sites on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/">WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-block-gif.gif" alt="" class="wp-image-42034" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Up your visual game with the Pinterest block</h3>
<p>Strong visuals help to provide inspiration, tell your stories, and sell your products and services. Pinterest is an engaging way for bloggers, influencers, and small business owners to enhance their site content and expand their following. With the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/embed-from-pinterest/">Pinterest block</a>, you can embed and share pins, boards, and profiles on your site. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/pinterest-block.png?w=1024" alt="" class="wp-image-42041" /></figure>
<p><strong>Quick-start guide: </strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Pinterest </strong>block.</li>
<li>Paste the URL of a pin, board, or profile you&#8217;d like to display and click <strong>Embed</strong>. Note that you can only embed public boards.</li>
<li><em>Pro tip:</em> in the block editor, go to <strong>Layout Elements</strong> and select <strong>Layout Grid</strong> to create a visually striking layout with pins, boards,  and profiles, as shown above.</li>
</ul>
<hr class="wp-block-separator" />
<h3>Display locations with the Map block</h3>
<p>A map on your site is a quick visual way to display a location, like your restaurant&#8217;s takeout window or the drop-off spot for donations to a local food bank. Powered by mapping platform Mapbox, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block</a> embeds a customized map on your site. Show the location of your business, a chain of boutique hotels, the meeting spots for your nonprofit&#8217;s volunteers, and more.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/map.png?w=1024" alt="" class="wp-image-42044" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Map </strong>block.</li>
<li>In the text field, type the location you want to display and select the correct location from among the results that appear.</li>
<li>Click on the red marker to edit the title and caption of the marker.</li>
<li>Explore the toolbar for block-specific settings. Add more markers, for example, by clicking the <strong>Add a marker</strong> button.</li>
<li>In the sidebar, customize your map&#8217;s appearance (including colors, height, and zoom level).</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Share your calendar with the Google Calendar block</h3>
<p>Are you an author planning a book tour (or a series of online readings)? A digital marketing consultant hosting social media workshops? A neighborhood pop-up bakery? With<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/"> the Google Calendar block</a>, you can display a calendar of upcoming events or your hours of operation.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/google-calendar.png?w=1024" alt="" class="wp-image-42049" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In Google Calendar, click the three dots next to your calendar name and select&nbsp;<strong>Settings and sharing</strong>. </li>
<li>Under <strong>Access Permissions</strong>, ensure <strong>Make available to public</strong> is checked. </li>
<li>Click on <strong>Integrate calendar</strong> on the left and copy the code under <strong>Embed code</strong>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button, search for and select the <strong>Custom HTML</strong> block, and paste the code you copied in Google Calendar.</li>
<li><strong>Publish</strong> your post or page. The next time you edit this post or page, you&#8217;ll see the code has been converted to shortcode.</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/">Google Calendar block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Streamline reservations with the OpenTable block</h3>
<p>If you&#8217;re a restaurant or cafe owner, a primary goal of your site is to increase the number of bookings. Sure, people aren&#8217;t dining out right now, but you can be ready to take reservations in the future. With the&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block</a>, people can reserve a table directly from a post or page instead of calling or booking through a different reservation service. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/standard.png?w=390" alt="" class="wp-image-42057" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, your restaurant must be listed on OpenTable. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://restaurant.opentable.com/">Create an OpenTable listing now</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>OpenTable </strong>block.</li>
<li>Enter your OpenTable Reservation Widget embed code. <a target="_blank" rel="nofollow" rel="noreferrer noopener" href="/redirect.php?URL=https://support.opentable.com/s/article/How-do-I-install-the-reservation-widget-to-take-reservations-on-my-website-and-Facebook?language=en_US" target="_blank">Check this OpenTable guide</a> if you need help.</li>
<li>Explore the block&#8217;s toolbar and sidebar settings. For example, choose from four different embed styles: <strong>Standard</strong>, <strong>Tall</strong>, <strong>Wide</strong>, and <strong>Button</strong>.</li>
<li>This block is currently available to sites on the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/"> WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/opentable-block.gif?w=600" alt="" class="wp-image-42058" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block support page</a>.</em></p>
<hr class="wp-block-separator" />
<p><strong>Which blocks are you most excited about? </strong></p>
<p><strong>Stay tuned for more new blocks soon! </strong></p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Your Business More Accessible with New Blocks</title>
		<link>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-6/</link>
		<comments>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-6/#comments</comments>
		<pubDate>Thu, 02 Apr 2020 16:21:18 +0000</pubDate>
		<dc:creator>claudialuca90</dc:creator>
				<category><![CDATA[Sicilia]]></category>
		<category><![CDATA[Access Permissions]]></category>
		<category><![CDATA[Add Block]]></category>
		<category><![CDATA[Eventbrite Checkout]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Layout Elements]]></category>
		<category><![CDATA[Layout Grid]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-6/</guid>
		<description><![CDATA[From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more&#160;<a href="https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-6/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more people.</p>
<p>Our team has been hard at work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/block-editor-upgrades/">improving the block editor experience</a>. We&#8217;ve launched six new blocks that integrate WordPress.com and Jetpack-enabled sites with popular services &#8212; Eventbrite, Calendly, Pinterest, Mapbox, Google Calendar, and OpenTable &#8212; enabling you to embed rich content and provide booking and scheduling options right on your blog or website. </p>
<p>Whether you&#8217;re an online boutique, a pilates studio, an independent consultant, or a local restaurant, these blocks offer you more ways to promote your brand or business. Take a look at each block &#8212; or simply jump to a specific one below.</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#eventbrite">Eventbrite</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#calendly">Calendly</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#pinterest">Pinterest</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#map">Mapbox</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#googlecalendar">Google Calendar</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#opentable">OpenTable</a></li>
</ul>
<hr class="wp-block-separator" />
<h3>Promote online events with the Eventbrite block</h3>
<p>Looking for a way to promote an online event (like your museum&#8217;s virtual curator talk or your company&#8217;s webinar on remote work), or even an at-home livestream performance for your fans and followers? Offering key features of the popular event registration platform, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block</a> embeds events on posts and pages so your visitors can register and purchase tickets right from your site.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block-image.png?w=1024" alt="" class="wp-image-42030" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need an Eventbrite account. If you don&#8217;t have one, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/signin/">sign up at Eventbrite for free</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Eventbrite Checkout</strong> block.</li>
<li>Enter the URL of your Eventbrite event. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/support/articles/en_US/How_To/how-to-customize-your-event-url-web-address?lg=en_US">Read these steps from Eventbrite</a> if you need help.</li>
<li>Select from two options: an <strong>In-page Embed</strong> shows the event details and registration options directly on your site. The <strong>Button &amp; Modal</strong> option shows just a button; when clicked, the event details will pop up so your visitor can register.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block.gif" alt="" class="wp-image-42029" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Schedule sessions with the Calendly block</h3>
<p>Want to make it easier for people to book private meditation sessions or language lessons with you? The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block</a>, featured recently in<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/move-your-classes-online/"> our guide on moving your classes online</a>, is a handy way for your clients and students to book a session directly on your site &#8212; eliminating the time spent coordinating schedules. You can also use the Calendly block to schedule team meetings or group events.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-image.png?w=1024" alt="" class="wp-image-42033" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need a Calendly account. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://calendly.com/signup">Create one for free at Calendly</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Calendly </strong>block.</li>
<li>Enter your Calendly web address or embed code. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://help.calendly.com/hc/en-us/articles/223147027-Embed-options-overview">Follow these steps from Calendly</a> if you need help.</li>
<li>Select from two styles: the <strong>Inline</strong>&nbsp;style embeds a calendar directly onto your site; the <strong>Link&nbsp;</strong>style inserts a button that a visitor can click to open a pop-up calendar.</li>
<li>This block is currently available to sites on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/">WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-block-gif.gif" alt="" class="wp-image-42034" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Up your visual game with the Pinterest block</h3>
<p>Strong visuals help to provide inspiration, tell your stories, and sell your products and services. Pinterest is an engaging way for bloggers, influencers, and small business owners to enhance their site content and expand their following. With the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/embed-from-pinterest/">Pinterest block</a>, you can embed and share pins, boards, and profiles on your site. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/pinterest-block.png?w=1024" alt="" class="wp-image-42041" /></figure>
<p><strong>Quick-start guide: </strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Pinterest </strong>block.</li>
<li>Paste the URL of a pin, board, or profile you&#8217;d like to display and click <strong>Embed</strong>. Note that you can only embed public boards.</li>
<li><em>Pro tip:</em> in the block editor, go to <strong>Layout Elements</strong> and select <strong>Layout Grid</strong> to create a visually striking layout with pins, boards,  and profiles, as shown above.</li>
</ul>
<hr class="wp-block-separator" />
<h3>Display locations with the Map block</h3>
<p>A map on your site is a quick visual way to display a location, like your restaurant&#8217;s takeout window or the drop-off spot for donations to a local food bank. Powered by mapping platform Mapbox, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block</a> embeds a customized map on your site. Show the location of your business, a chain of boutique hotels, the meeting spots for your nonprofit&#8217;s volunteers, and more.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/map.png?w=1024" alt="" class="wp-image-42044" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Map </strong>block.</li>
<li>In the text field, type the location you want to display and select the correct location from among the results that appear.</li>
<li>Click on the red marker to edit the title and caption of the marker.</li>
<li>Explore the toolbar for block-specific settings. Add more markers, for example, by clicking the <strong>Add a marker</strong> button.</li>
<li>In the sidebar, customize your map&#8217;s appearance (including colors, height, and zoom level).</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Share your calendar with the Google Calendar block</h3>
<p>Are you an author planning a book tour (or a series of online readings)? A digital marketing consultant hosting social media workshops? A neighborhood pop-up bakery? With<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/"> the Google Calendar block</a>, you can display a calendar of upcoming events or your hours of operation.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/google-calendar.png?w=1024" alt="" class="wp-image-42049" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In Google Calendar, click the three dots next to your calendar name and select&nbsp;<strong>Settings and sharing</strong>. </li>
<li>Under <strong>Access Permissions</strong>, ensure <strong>Make available to public</strong> is checked. </li>
<li>Click on <strong>Integrate calendar</strong> on the left and copy the code under <strong>Embed code</strong>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button, search for and select the <strong>Custom HTML</strong> block, and paste the code you copied in Google Calendar.</li>
<li><strong>Publish</strong> your post or page. The next time you edit this post or page, you&#8217;ll see the code has been converted to shortcode.</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/">Google Calendar block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Streamline reservations with the OpenTable block</h3>
<p>If you&#8217;re a restaurant or cafe owner, a primary goal of your site is to increase the number of bookings. Sure, people aren&#8217;t dining out right now, but you can be ready to take reservations in the future. With the&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block</a>, people can reserve a table directly from a post or page instead of calling or booking through a different reservation service. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/standard.png?w=390" alt="" class="wp-image-42057" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, your restaurant must be listed on OpenTable. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://restaurant.opentable.com/">Create an OpenTable listing now</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>OpenTable </strong>block.</li>
<li>Enter your OpenTable Reservation Widget embed code. <a target="_blank" rel="nofollow" rel="noreferrer noopener" href="/redirect.php?URL=https://support.opentable.com/s/article/How-do-I-install-the-reservation-widget-to-take-reservations-on-my-website-and-Facebook?language=en_US" target="_blank">Check this OpenTable guide</a> if you need help.</li>
<li>Explore the block&#8217;s toolbar and sidebar settings. For example, choose from four different embed styles: <strong>Standard</strong>, <strong>Tall</strong>, <strong>Wide</strong>, and <strong>Button</strong>.</li>
<li>This block is currently available to sites on the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/"> WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/opentable-block.gif?w=600" alt="" class="wp-image-42058" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block support page</a>.</em></p>
<hr class="wp-block-separator" />
<p><strong>Which blocks are you most excited about? </strong></p>
<p><strong>Stay tuned for more new blocks soon! </strong></p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Your Business More Accessible with New Blocks</title>
		<link>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-5/</link>
		<comments>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-5/#comments</comments>
		<pubDate>Thu, 02 Apr 2020 16:21:18 +0000</pubDate>
		<dc:creator>BucciaDiArancia</dc:creator>
				<category><![CDATA[Piemonte]]></category>
		<category><![CDATA[Access Permissions]]></category>
		<category><![CDATA[Add Block]]></category>
		<category><![CDATA[Eventbrite Checkout]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Layout Elements]]></category>
		<category><![CDATA[Layout Grid]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-5/</guid>
		<description><![CDATA[From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more&#160;<a href="https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-5/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>From our support sessions with customers each month, we know that growing your brand or business is a top website goal. And in this unprecedented time in which more people around the world are staying at home, it&#8217;s important to promote your products and services online to reach a wider audience and connect with more people.</p>
<p>Our team has been hard at work <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/block-editor-upgrades/">improving the block editor experience</a>. We&#8217;ve launched six new blocks that integrate WordPress.com and Jetpack-enabled sites with popular services &#8212; Eventbrite, Calendly, Pinterest, Mapbox, Google Calendar, and OpenTable &#8212; enabling you to embed rich content and provide booking and scheduling options right on your blog or website. </p>
<p>Whether you&#8217;re an online boutique, a pilates studio, an independent consultant, or a local restaurant, these blocks offer you more ways to promote your brand or business. Take a look at each block &#8212; or simply jump to a specific one below.</p>
<ul>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#eventbrite">Eventbrite</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#calendly">Calendly</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#pinterest">Pinterest</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#map">Mapbox</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#googlecalendar">Google Calendar</a></li>
<li><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/feed/#opentable">OpenTable</a></li>
</ul>
<hr class="wp-block-separator" />
<h3>Promote online events with the Eventbrite block</h3>
<p>Looking for a way to promote an online event (like your museum&#8217;s virtual curator talk or your company&#8217;s webinar on remote work), or even an at-home livestream performance for your fans and followers? Offering key features of the popular event registration platform, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block</a> embeds events on posts and pages so your visitors can register and purchase tickets right from your site.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block-image.png?w=1024" alt="" class="wp-image-42030" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need an Eventbrite account. If you don&#8217;t have one, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/signin/">sign up at Eventbrite for free</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Eventbrite Checkout</strong> block.</li>
<li>Enter the URL of your Eventbrite event. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.eventbrite.com/support/articles/en_US/How_To/how-to-customize-your-event-url-web-address?lg=en_US">Read these steps from Eventbrite</a> if you need help.</li>
<li>Select from two options: an <strong>In-page Embed</strong> shows the event details and registration options directly on your site. The <strong>Button &amp; Modal</strong> option shows just a button; when clicked, the event details will pop up so your visitor can register.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/eventbrite-block.gif" alt="" class="wp-image-42029" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/eventbrite-block/">Eventbrite block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Schedule sessions with the Calendly block</h3>
<p>Want to make it easier for people to book private meditation sessions or language lessons with you? The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block</a>, featured recently in<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/blog/2020/03/26/move-your-classes-online/"> our guide on moving your classes online</a>, is a handy way for your clients and students to book a session directly on your site &#8212; eliminating the time spent coordinating schedules. You can also use the Calendly block to schedule team meetings or group events.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-image.png?w=1024" alt="" class="wp-image-42033" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, you need a Calendly account. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://calendly.com/signup">Create one for free at Calendly</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Calendly </strong>block.</li>
<li>Enter your Calendly web address or embed code. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://help.calendly.com/hc/en-us/articles/223147027-Embed-options-overview">Follow these steps from Calendly</a> if you need help.</li>
<li>Select from two styles: the <strong>Inline</strong>&nbsp;style embeds a calendar directly onto your site; the <strong>Link&nbsp;</strong>style inserts a button that a visitor can click to open a pop-up calendar.</li>
<li>This block is currently available to sites on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/">WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/calendly-block-gif.gif" alt="" class="wp-image-42034" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/calendly-block/">Calendly block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Up your visual game with the Pinterest block</h3>
<p>Strong visuals help to provide inspiration, tell your stories, and sell your products and services. Pinterest is an engaging way for bloggers, influencers, and small business owners to enhance their site content and expand their following. With the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/embed-from-pinterest/">Pinterest block</a>, you can embed and share pins, boards, and profiles on your site. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/pinterest-block.png?w=1024" alt="" class="wp-image-42041" /></figure>
<p><strong>Quick-start guide: </strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Pinterest </strong>block.</li>
<li>Paste the URL of a pin, board, or profile you&#8217;d like to display and click <strong>Embed</strong>. Note that you can only embed public boards.</li>
<li><em>Pro tip:</em> in the block editor, go to <strong>Layout Elements</strong> and select <strong>Layout Grid</strong> to create a visually striking layout with pins, boards,  and profiles, as shown above.</li>
</ul>
<hr class="wp-block-separator" />
<h3>Display locations with the Map block</h3>
<p>A map on your site is a quick visual way to display a location, like your restaurant&#8217;s takeout window or the drop-off spot for donations to a local food bank. Powered by mapping platform Mapbox, the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block</a> embeds a customized map on your site. Show the location of your business, a chain of boutique hotels, the meeting spots for your nonprofit&#8217;s volunteers, and more.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/map.png?w=1024" alt="" class="wp-image-42044" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>Map </strong>block.</li>
<li>In the text field, type the location you want to display and select the correct location from among the results that appear.</li>
<li>Click on the red marker to edit the title and caption of the marker.</li>
<li>Explore the toolbar for block-specific settings. Add more markers, for example, by clicking the <strong>Add a marker</strong> button.</li>
<li>In the sidebar, customize your map&#8217;s appearance (including colors, height, and zoom level).</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/map-block/">Map block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Share your calendar with the Google Calendar block</h3>
<p>Are you an author planning a book tour (or a series of online readings)? A digital marketing consultant hosting social media workshops? A neighborhood pop-up bakery? With<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/"> the Google Calendar block</a>, you can display a calendar of upcoming events or your hours of operation.</p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/google-calendar.png?w=1024" alt="" class="wp-image-42049" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>In Google Calendar, click the three dots next to your calendar name and select&nbsp;<strong>Settings and sharing</strong>. </li>
<li>Under <strong>Access Permissions</strong>, ensure <strong>Make available to public</strong> is checked. </li>
<li>Click on <strong>Integrate calendar</strong> on the left and copy the code under <strong>Embed code</strong>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button, search for and select the <strong>Custom HTML</strong> block, and paste the code you copied in Google Calendar.</li>
<li><strong>Publish</strong> your post or page. The next time you edit this post or page, you&#8217;ll see the code has been converted to shortcode.</li>
</ul>
<p><em>Explore more settings on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/google-calendar/">Google Calendar block support page</a>.</em></p>
<hr class="wp-block-separator" />
<h3>Streamline reservations with the OpenTable block</h3>
<p>If you&#8217;re a restaurant or cafe owner, a primary goal of your site is to increase the number of bookings. Sure, people aren&#8217;t dining out right now, but you can be ready to take reservations in the future. With the&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block</a>, people can reserve a table directly from a post or page instead of calling or booking through a different reservation service. </p>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/standard.png?w=390" alt="" class="wp-image-42057" /></figure>
<p><strong>Quick-start guide:</strong></p>
<ul>
<li>To use this block, your restaurant must be listed on OpenTable. <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://restaurant.opentable.com/">Create an OpenTable listing now</a>.</li>
<li>In the block editor, click the&nbsp;<strong>Add Block</strong>&nbsp;(<strong>+</strong>) button and search for and select the <strong>OpenTable </strong>block.</li>
<li>Enter your OpenTable Reservation Widget embed code. <a target="_blank" rel="nofollow" rel="noreferrer noopener" href="/redirect.php?URL=https://support.opentable.com/s/article/How-do-I-install-the-reservation-widget-to-take-reservations-on-my-website-and-Facebook?language=en_US" target="_blank">Check this OpenTable guide</a> if you need help.</li>
<li>Explore the block&#8217;s toolbar and sidebar settings. For example, choose from four different embed styles: <strong>Standard</strong>, <strong>Tall</strong>, <strong>Wide</strong>, and <strong>Button</strong>.</li>
<li>This block is currently available to sites on the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/pricing/"> WordPress.com Premium, Business, or eCommerce plans</a>. It&#8217;s free on Jetpack sites.</li>
</ul>
<figure><img src="https://en-blog.files.wordpress.com/2020/03/opentable-block.gif?w=600" alt="" class="wp-image-42058" /></figure>
<p><em>Learn more on the <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/wordpress-editor/blocks/opentable-block/">OpenTable block support page</a>.</em></p>
<hr class="wp-block-separator" />
<p><strong>Which blocks are you most excited about? </strong></p>
<p><strong>Stay tuned for more new blocks soon! </strong></p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/make-your-business-more-accessible-with-new-blocks-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- Wp Fastest Cache: XML Content -->