<?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; PHP</title>
	<atom:link href="https://foodbloggermania.it/tag/ricette/php/feed/" rel="self" type="application/rss+xml" />
	<link>https://foodbloggermania.it</link>
	<description>Food Blogger Mania</description>
	<lastBuildDate>Mon, 06 Jul 2026 08:20:39 +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>Fix WordPress Errors, Bugs &amp; Issues Quickly for $10</title>
		<link>https://foodbloggermania.it/ricetta/fix-wordpress-errors-bugs-issues-quickly-for-10/</link>
		<comments>https://foodbloggermania.it/ricetta/fix-wordpress-errors-bugs-issues-quickly-for-10/#comments</comments>
		<pubDate>Sun, 03 May 2026 20:26:26 +0000</pubDate>
		<dc:creator>Ivy</dc:creator>
				<category><![CDATA[Toscana]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme Plugin]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/fix-wordpress-errors-bugs-issues-quickly-for-10/</guid>
		<description><![CDATA[Do you have any trouble with your WordPress website? My WordPress troubleshooting service helps you solve all types of technical issues for quick and effective results! I will solve: Theme / Plugin conflict Website error (500, 404, white screen) CSS/PHP/JavaScript error Speed/performance problem Malware/security issue Responsive design error ✅ Fast support ✅ Safe and clean&#160;<a href="https://foodbloggermania.it/ricetta/fix-wordpress-errors-bugs-issues-quickly-for-10/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>Do you have any trouble with your WordPress website? My WordPress troubleshooting service helps you solve all types of technical issues for quick and effective results!</p>
<p>I will solve:<br />
 Theme / Plugin conflict Website error (500, 404, white screen) CSS/PHP/JavaScript error Speed/performance problem Malware/security issue Responsive design error<br />
✅ Fast support<br />
✅ Safe and clean solution<br />
✅ 100% customer satisfaction</p>
<p>Leave it to me to fix your bugs while you concentrate on expanding your business! ????</p>
<p>by: <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.seoclerk.com/user/seoservices2028">seoservices2028</a><br />Created: &#8211;<br />Category: <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.seoclerk.com/categories/wordpress-programming">WordPress</a><br />Viewed: 248</p>
<p>
<hr />
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/fix-wordpress-errors-bugs-issues-quickly-for-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-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/</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>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-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-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-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-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-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-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-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-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>Case Study: Jelly Pixel Studio’s Journey With WordPress.com</title>
		<link>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-11/</link>
		<comments>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-11/#comments</comments>
		<pubDate>Wed, 06 Mar 2024 21:06:28 +0000</pubDate>
		<dc:creator>ricette da coinquiline</dc:creator>
				<category><![CDATA[Campania]]></category>
		<category><![CDATA[Case Study]]></category>
		<category><![CDATA[Dika Fei]]></category>
		<category><![CDATA[Jelly Pixel]]></category>
		<category><![CDATA[LITERALLY]]></category>
		<category><![CDATA[MAGIC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WP]]></category>
		<category><![CDATA[YES]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-11/</guid>
		<description><![CDATA[Jelly Pixel Studio, a web development agency based in Indonesia, specializes in crafting unique and illustrative websites for clients worldwide. The company serves a wide variety of clients, from small businesses to larger corporations, utilizing WordPress.com as their primary hosting platform due to its exceptional stability, fast performance, and robust features. Over the years, the&#160;<a href="https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-11/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a>, a web development agency based in Indonesia, specializes in crafting unique and illustrative websites for clients worldwide. The company serves a wide variety of clients, from small businesses to larger corporations, utilizing WordPress.com as their primary hosting platform due to its exceptional stability, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/site-performance/">fast performance</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/platform-features/">robust features</a>. </p>
<p>Over the years, the agency has migrated numerous websites to WordPress.com and has seen consistent uptime and improved efficiency, saving both time and money. The agency’s founder, Andika Purnawijaya, better known as Dika Fei, cites WordPress.com as the magic solution that helped solve many hosting challenges for the agency’s clients. </p>
<p>Let&#8217;s explore a bit more about Jelly Pixel and how WordPress.com helps keep their clients happy. </p>
<h2>Dika&#8217;s path to web development</h2>
<p>Dika Fei embarked on his web development journey right after university, learning and mastering IBM’s WebSphere. His first interaction with WordPress.com came when he joined <a target="_blank" rel="nofollow" href="/redirect.php?URL=http://codeable.com">Codeable</a> to work with various clients whose sites were hosted on the WordPress.com platform. Dika saw the immense value in WordPress.com and adopted it for the majority of his projects.</p>
<p>Jelly Pixel Studio was born out of a failed startup venture by Dika and three of his friends from college. After their initial attempt at creating something similar to Shopify for the Indonesian market didn’t work out, the team decided to channel their expertise into a highly successful web development agency. When choosing a platform, they settled on WordPress due to its simplicity and intuitiveness.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-wp-stronk.png"><img width="1024" height="550" src="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-wp-stronk.png" alt="The Jelly Pixel and WP Stronk logos" class="wp-image-54744" style="width:618px;height:auto" /></a></figure>
</div>
<p>The team later branched out to form a second agency,&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a>, which handles subscription-based web maintenance and content entry.</p>
<p>When asked if the agencies focused on any specific niche, Dika said, &#8220;YES! Jelly Pixel is exceptionally skilled at creating illustrative websites with subtle scrolling animations. Our websites leave a lasting impression even after you close the tab.&#8221;</p>
<h2>The impact of WordPress.com</h2>
<p>WordPress.com has been instrumental in helping Jelly Pixel Studio streamline its operations and deliver outstanding services to clients. With a mix of projects in maintenance and those being actively developed, Dika and his team of seven, or “the magnificent seven” as they like to call themselves, have benefited greatly from the platform’s robust features and top-notch performance.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-team-wordpress.png"><img width="1600" height="1192" src="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-team-wordpress.png" alt="The Jelly Pixel Studio team" class="wp-image-54742" /></a></figure>
<p>WordPress developers and agencies are no strangers to the perils and pitfalls of hosting. But WordPress.com solves those problems for Jelly Pixel Studio clients:</p>
<blockquote>
<p>What I love about WordPress.com is its exceptional stability and blazing-fast performance, regardless of your setup. Even with other managed hosting providers, you often need to be mindful of  various settings such as: cache parameters and PHP workers. However, with WordPress.com, <strong>everything just works</strong> seamlessly. <strong>It’s a true “set it and forget it” experience</strong>. </p>
<p>As long as your site is hosted on WordPress.com, you can rest assured that it won’t go down and it won’t slow down, no matter the traffic. I have no idea how you accomplished it, but it’s absolutely AMAZING! </p>
</blockquote>
<h2>Literally magic </h2>
<p>The team considers WordPress.com to be a good fit for their clients. Why?</p>
<blockquote>
<p>You have amazing support, and your infrastructure is <strong>LITERALLY MAGIC</strong>. We have monitored our clients’ uptime, and 100% is a number we often see. How is this even possible? “Amazing” would be an understatement. You have saved me from a ton of urgent calls at night.</p>
</blockquote>
<p>Jelly Pixel Studio believes WordPress.com has one well-kept secret:</p>
<blockquote>
<p>I firmly believe that WordPress.com is the best hosting option for WooCommerce, particularly those with high traffic. </p>
</blockquote>
<p>He thinks this is a missed opportunity for many freelancers and agencies who may not have considered using WordPress.com for their hosting clients. He shares this example:</p>
<blockquote>
<p>I have a client on a different host. They get HUGE traffic. Every time they have a sale, they need to purchase a package upgrade and I have to constantly monitor their ad parameters to ensure proper caching. With the way WordPress.com works, all of this would be seamlessly handled out of the box.</p>
</blockquote>
<p>He adds:</p>
<blockquote>
<p>Unfortunately, the knowledge of WordPress.com as a highly stable WooCommerce hosting solution seems to have been lost over time. It almost feels like a well-kept secret! </p>
</blockquote>
<h2>The verdict</h2>
<p>Dika and his team at Jelly Pixel Studio view WordPress.com as a valuable partner in their web development journey. Dika credits the platform for providing peace of mind, leading to a happier and more productive work environment for his team, as well as clients who no longer complain about their site’s performance. He looks forward to further cooperation with WordPress.com and hopes for the continued evolution of the platform’s capabilities.</p>
<p>At the heart of his work, Dika stands by this quote from Victor Frankl: </p>
<blockquote>
<p>“For success, like happiness, cannot be pursued; it must ensue, and it only does so as the unintended side-effect of one’s personal dedication to a cause greater than oneself.” </p>
</blockquote>
<p>This approach is echoed in the success story of <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a>, marking the agencies as businesses of kindness, dedication, and commitment to problem-solving.</p>
<h2>The power of hosting with WordPress.com </h2>
<p>WordPress web design and development agencies are discovering <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/">the power of WordPress.com hosting</a> and the benefits it offers their clients. With <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/site-performance/">full-stack performance</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/platform-features/account-security/">robust security</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/">developer-friendly features</a>, WordPress.com provides agencies with a platform they can confidently recommend to their clients.</p>
<p>If you&#8217;re<strong> </strong>interested in getting access to the tools and features on WordPress.com that can support your development process, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here to enable our “I am a developer” setting</a> on your WordPress.com account.</p>
<p>Finally, if you&#8217;re in search of an agency specializing in illustrative websites and CRO (Conversion Rate Optimization), <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a> can help you. For web and content maintenance, check out <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a> for their comprehensive services.</p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Study: Jelly Pixel Studio’s Journey With WordPress.com</title>
		<link>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-4/</link>
		<comments>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-4/#comments</comments>
		<pubDate>Wed, 06 Mar 2024 21:06:28 +0000</pubDate>
		<dc:creator>Alveare Delle Delizie</dc:creator>
				<category><![CDATA[Friuli Venezia Giulia]]></category>
		<category><![CDATA[Case Study]]></category>
		<category><![CDATA[Dika Fei]]></category>
		<category><![CDATA[Jelly Pixel]]></category>
		<category><![CDATA[LITERALLY]]></category>
		<category><![CDATA[MAGIC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WP]]></category>
		<category><![CDATA[YES]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-4/</guid>
		<description><![CDATA[Jelly Pixel Studio, a web development agency based in Indonesia, specializes in crafting unique and illustrative websites for clients worldwide. The company serves a wide variety of clients, from small businesses to larger corporations, utilizing WordPress.com as their primary hosting platform due to its exceptional stability, fast performance, and robust features. Over the years, the&#160;<a href="https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-4/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a>, a web development agency based in Indonesia, specializes in crafting unique and illustrative websites for clients worldwide. The company serves a wide variety of clients, from small businesses to larger corporations, utilizing WordPress.com as their primary hosting platform due to its exceptional stability, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/site-performance/">fast performance</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/platform-features/">robust features</a>. </p>
<p>Over the years, the agency has migrated numerous websites to WordPress.com and has seen consistent uptime and improved efficiency, saving both time and money. The agency’s founder, Andika Purnawijaya, better known as Dika Fei, cites WordPress.com as the magic solution that helped solve many hosting challenges for the agency’s clients. </p>
<p>Let&#8217;s explore a bit more about Jelly Pixel and how WordPress.com helps keep their clients happy. </p>
<h2>Dika&#8217;s path to web development</h2>
<p>Dika Fei embarked on his web development journey right after university, learning and mastering IBM’s WebSphere. His first interaction with WordPress.com came when he joined <a target="_blank" rel="nofollow" href="/redirect.php?URL=http://codeable.com">Codeable</a> to work with various clients whose sites were hosted on the WordPress.com platform. Dika saw the immense value in WordPress.com and adopted it for the majority of his projects.</p>
<p>Jelly Pixel Studio was born out of a failed startup venture by Dika and three of his friends from college. After their initial attempt at creating something similar to Shopify for the Indonesian market didn’t work out, the team decided to channel their expertise into a highly successful web development agency. When choosing a platform, they settled on WordPress due to its simplicity and intuitiveness.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-wp-stronk.png"><img width="1024" height="550" src="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-wp-stronk.png" alt="The Jelly Pixel and WP Stronk logos" class="wp-image-54744" style="width:618px;height:auto" /></a></figure>
</div>
<p>The team later branched out to form a second agency,&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a>, which handles subscription-based web maintenance and content entry.</p>
<p>When asked if the agencies focused on any specific niche, Dika said, &#8220;YES! Jelly Pixel is exceptionally skilled at creating illustrative websites with subtle scrolling animations. Our websites leave a lasting impression even after you close the tab.&#8221;</p>
<h2>The impact of WordPress.com</h2>
<p>WordPress.com has been instrumental in helping Jelly Pixel Studio streamline its operations and deliver outstanding services to clients. With a mix of projects in maintenance and those being actively developed, Dika and his team of seven, or “the magnificent seven” as they like to call themselves, have benefited greatly from the platform’s robust features and top-notch performance.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-team-wordpress.png"><img width="1600" height="1192" src="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-team-wordpress.png" alt="The Jelly Pixel Studio team" class="wp-image-54742" /></a></figure>
<p>WordPress developers and agencies are no strangers to the perils and pitfalls of hosting. But WordPress.com solves those problems for Jelly Pixel Studio clients:</p>
<blockquote>
<p>What I love about WordPress.com is its exceptional stability and blazing-fast performance, regardless of your setup. Even with other managed hosting providers, you often need to be mindful of  various settings such as: cache parameters and PHP workers. However, with WordPress.com, <strong>everything just works</strong> seamlessly. <strong>It’s a true “set it and forget it” experience</strong>. </p>
<p>As long as your site is hosted on WordPress.com, you can rest assured that it won’t go down and it won’t slow down, no matter the traffic. I have no idea how you accomplished it, but it’s absolutely AMAZING! </p>
</blockquote>
<h2>Literally magic </h2>
<p>The team considers WordPress.com to be a good fit for their clients. Why?</p>
<blockquote>
<p>You have amazing support, and your infrastructure is <strong>LITERALLY MAGIC</strong>. We have monitored our clients’ uptime, and 100% is a number we often see. How is this even possible? “Amazing” would be an understatement. You have saved me from a ton of urgent calls at night.</p>
</blockquote>
<p>Jelly Pixel Studio believes WordPress.com has one well-kept secret:</p>
<blockquote>
<p>I firmly believe that WordPress.com is the best hosting option for WooCommerce, particularly those with high traffic. </p>
</blockquote>
<p>He thinks this is a missed opportunity for many freelancers and agencies who may not have considered using WordPress.com for their hosting clients. He shares this example:</p>
<blockquote>
<p>I have a client on a different host. They get HUGE traffic. Every time they have a sale, they need to purchase a package upgrade and I have to constantly monitor their ad parameters to ensure proper caching. With the way WordPress.com works, all of this would be seamlessly handled out of the box.</p>
</blockquote>
<p>He adds:</p>
<blockquote>
<p>Unfortunately, the knowledge of WordPress.com as a highly stable WooCommerce hosting solution seems to have been lost over time. It almost feels like a well-kept secret! </p>
</blockquote>
<h2>The verdict</h2>
<p>Dika and his team at Jelly Pixel Studio view WordPress.com as a valuable partner in their web development journey. Dika credits the platform for providing peace of mind, leading to a happier and more productive work environment for his team, as well as clients who no longer complain about their site’s performance. He looks forward to further cooperation with WordPress.com and hopes for the continued evolution of the platform’s capabilities.</p>
<p>At the heart of his work, Dika stands by this quote from Victor Frankl: </p>
<blockquote>
<p>“For success, like happiness, cannot be pursued; it must ensue, and it only does so as the unintended side-effect of one’s personal dedication to a cause greater than oneself.” </p>
</blockquote>
<p>This approach is echoed in the success story of <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a>, marking the agencies as businesses of kindness, dedication, and commitment to problem-solving.</p>
<h2>The power of hosting with WordPress.com </h2>
<p>WordPress web design and development agencies are discovering <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/">the power of WordPress.com hosting</a> and the benefits it offers their clients. With <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/site-performance/">full-stack performance</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/platform-features/account-security/">robust security</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/">developer-friendly features</a>, WordPress.com provides agencies with a platform they can confidently recommend to their clients.</p>
<p>If you&#8217;re<strong> </strong>interested in getting access to the tools and features on WordPress.com that can support your development process, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here to enable our “I am a developer” setting</a> on your WordPress.com account.</p>
<p>Finally, if you&#8217;re in search of an agency specializing in illustrative websites and CRO (Conversion Rate Optimization), <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a> can help you. For web and content maintenance, check out <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a> for their comprehensive services.</p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Study: Jelly Pixel Studio’s Journey With WordPress.com</title>
		<link>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-5/</link>
		<comments>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-5/#comments</comments>
		<pubDate>Wed, 06 Mar 2024 21:06:28 +0000</pubDate>
		<dc:creator>BucciaDiArancia</dc:creator>
				<category><![CDATA[Piemonte]]></category>
		<category><![CDATA[Case Study]]></category>
		<category><![CDATA[Dika Fei]]></category>
		<category><![CDATA[Jelly Pixel]]></category>
		<category><![CDATA[LITERALLY]]></category>
		<category><![CDATA[MAGIC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WP]]></category>
		<category><![CDATA[YES]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-5/</guid>
		<description><![CDATA[Jelly Pixel Studio, a web development agency based in Indonesia, specializes in crafting unique and illustrative websites for clients worldwide. The company serves a wide variety of clients, from small businesses to larger corporations, utilizing WordPress.com as their primary hosting platform due to its exceptional stability, fast performance, and robust features. Over the years, the&#160;<a href="https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-5/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a>, a web development agency based in Indonesia, specializes in crafting unique and illustrative websites for clients worldwide. The company serves a wide variety of clients, from small businesses to larger corporations, utilizing WordPress.com as their primary hosting platform due to its exceptional stability, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/site-performance/">fast performance</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/platform-features/">robust features</a>. </p>
<p>Over the years, the agency has migrated numerous websites to WordPress.com and has seen consistent uptime and improved efficiency, saving both time and money. The agency’s founder, Andika Purnawijaya, better known as Dika Fei, cites WordPress.com as the magic solution that helped solve many hosting challenges for the agency’s clients. </p>
<p>Let&#8217;s explore a bit more about Jelly Pixel and how WordPress.com helps keep their clients happy. </p>
<h2>Dika&#8217;s path to web development</h2>
<p>Dika Fei embarked on his web development journey right after university, learning and mastering IBM’s WebSphere. His first interaction with WordPress.com came when he joined <a target="_blank" rel="nofollow" href="/redirect.php?URL=http://codeable.com">Codeable</a> to work with various clients whose sites were hosted on the WordPress.com platform. Dika saw the immense value in WordPress.com and adopted it for the majority of his projects.</p>
<p>Jelly Pixel Studio was born out of a failed startup venture by Dika and three of his friends from college. After their initial attempt at creating something similar to Shopify for the Indonesian market didn’t work out, the team decided to channel their expertise into a highly successful web development agency. When choosing a platform, they settled on WordPress due to its simplicity and intuitiveness.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-wp-stronk.png"><img width="1024" height="550" src="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-wp-stronk.png" alt="The Jelly Pixel and WP Stronk logos" class="wp-image-54744" style="width:618px;height:auto" /></a></figure>
</div>
<p>The team later branched out to form a second agency,&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a>, which handles subscription-based web maintenance and content entry.</p>
<p>When asked if the agencies focused on any specific niche, Dika said, &#8220;YES! Jelly Pixel is exceptionally skilled at creating illustrative websites with subtle scrolling animations. Our websites leave a lasting impression even after you close the tab.&#8221;</p>
<h2>The impact of WordPress.com</h2>
<p>WordPress.com has been instrumental in helping Jelly Pixel Studio streamline its operations and deliver outstanding services to clients. With a mix of projects in maintenance and those being actively developed, Dika and his team of seven, or “the magnificent seven” as they like to call themselves, have benefited greatly from the platform’s robust features and top-notch performance.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-team-wordpress.png"><img width="1600" height="1192" src="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-team-wordpress.png" alt="The Jelly Pixel Studio team" class="wp-image-54742" /></a></figure>
<p>WordPress developers and agencies are no strangers to the perils and pitfalls of hosting. But WordPress.com solves those problems for Jelly Pixel Studio clients:</p>
<blockquote>
<p>What I love about WordPress.com is its exceptional stability and blazing-fast performance, regardless of your setup. Even with other managed hosting providers, you often need to be mindful of  various settings such as: cache parameters and PHP workers. However, with WordPress.com, <strong>everything just works</strong> seamlessly. <strong>It’s a true “set it and forget it” experience</strong>. </p>
<p>As long as your site is hosted on WordPress.com, you can rest assured that it won’t go down and it won’t slow down, no matter the traffic. I have no idea how you accomplished it, but it’s absolutely AMAZING! </p>
</blockquote>
<h2>Literally magic </h2>
<p>The team considers WordPress.com to be a good fit for their clients. Why?</p>
<blockquote>
<p>You have amazing support, and your infrastructure is <strong>LITERALLY MAGIC</strong>. We have monitored our clients’ uptime, and 100% is a number we often see. How is this even possible? “Amazing” would be an understatement. You have saved me from a ton of urgent calls at night.</p>
</blockquote>
<p>Jelly Pixel Studio believes WordPress.com has one well-kept secret:</p>
<blockquote>
<p>I firmly believe that WordPress.com is the best hosting option for WooCommerce, particularly those with high traffic. </p>
</blockquote>
<p>He thinks this is a missed opportunity for many freelancers and agencies who may not have considered using WordPress.com for their hosting clients. He shares this example:</p>
<blockquote>
<p>I have a client on a different host. They get HUGE traffic. Every time they have a sale, they need to purchase a package upgrade and I have to constantly monitor their ad parameters to ensure proper caching. With the way WordPress.com works, all of this would be seamlessly handled out of the box.</p>
</blockquote>
<p>He adds:</p>
<blockquote>
<p>Unfortunately, the knowledge of WordPress.com as a highly stable WooCommerce hosting solution seems to have been lost over time. It almost feels like a well-kept secret! </p>
</blockquote>
<h2>The verdict</h2>
<p>Dika and his team at Jelly Pixel Studio view WordPress.com as a valuable partner in their web development journey. Dika credits the platform for providing peace of mind, leading to a happier and more productive work environment for his team, as well as clients who no longer complain about their site’s performance. He looks forward to further cooperation with WordPress.com and hopes for the continued evolution of the platform’s capabilities.</p>
<p>At the heart of his work, Dika stands by this quote from Victor Frankl: </p>
<blockquote>
<p>“For success, like happiness, cannot be pursued; it must ensue, and it only does so as the unintended side-effect of one’s personal dedication to a cause greater than oneself.” </p>
</blockquote>
<p>This approach is echoed in the success story of <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a>, marking the agencies as businesses of kindness, dedication, and commitment to problem-solving.</p>
<h2>The power of hosting with WordPress.com </h2>
<p>WordPress web design and development agencies are discovering <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/">the power of WordPress.com hosting</a> and the benefits it offers their clients. With <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/site-performance/">full-stack performance</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/platform-features/account-security/">robust security</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/">developer-friendly features</a>, WordPress.com provides agencies with a platform they can confidently recommend to their clients.</p>
<p>If you&#8217;re<strong> </strong>interested in getting access to the tools and features on WordPress.com that can support your development process, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here to enable our “I am a developer” setting</a> on your WordPress.com account.</p>
<p>Finally, if you&#8217;re in search of an agency specializing in illustrative websites and CRO (Conversion Rate Optimization), <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a> can help you. For web and content maintenance, check out <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a> for their comprehensive services.</p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Study: Jelly Pixel Studio’s Journey With WordPress.com</title>
		<link>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-6/</link>
		<comments>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-6/#comments</comments>
		<pubDate>Wed, 06 Mar 2024 21:06:28 +0000</pubDate>
		<dc:creator>claudialuca90</dc:creator>
				<category><![CDATA[Sicilia]]></category>
		<category><![CDATA[Case Study]]></category>
		<category><![CDATA[Dika Fei]]></category>
		<category><![CDATA[Jelly Pixel]]></category>
		<category><![CDATA[LITERALLY]]></category>
		<category><![CDATA[MAGIC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WP]]></category>
		<category><![CDATA[YES]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-6/</guid>
		<description><![CDATA[Jelly Pixel Studio, a web development agency based in Indonesia, specializes in crafting unique and illustrative websites for clients worldwide. The company serves a wide variety of clients, from small businesses to larger corporations, utilizing WordPress.com as their primary hosting platform due to its exceptional stability, fast performance, and robust features. Over the years, the&#160;<a href="https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-6/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a>, a web development agency based in Indonesia, specializes in crafting unique and illustrative websites for clients worldwide. The company serves a wide variety of clients, from small businesses to larger corporations, utilizing WordPress.com as their primary hosting platform due to its exceptional stability, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/site-performance/">fast performance</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/platform-features/">robust features</a>. </p>
<p>Over the years, the agency has migrated numerous websites to WordPress.com and has seen consistent uptime and improved efficiency, saving both time and money. The agency’s founder, Andika Purnawijaya, better known as Dika Fei, cites WordPress.com as the magic solution that helped solve many hosting challenges for the agency’s clients. </p>
<p>Let&#8217;s explore a bit more about Jelly Pixel and how WordPress.com helps keep their clients happy. </p>
<h2>Dika&#8217;s path to web development</h2>
<p>Dika Fei embarked on his web development journey right after university, learning and mastering IBM’s WebSphere. His first interaction with WordPress.com came when he joined <a target="_blank" rel="nofollow" href="/redirect.php?URL=http://codeable.com">Codeable</a> to work with various clients whose sites were hosted on the WordPress.com platform. Dika saw the immense value in WordPress.com and adopted it for the majority of his projects.</p>
<p>Jelly Pixel Studio was born out of a failed startup venture by Dika and three of his friends from college. After their initial attempt at creating something similar to Shopify for the Indonesian market didn’t work out, the team decided to channel their expertise into a highly successful web development agency. When choosing a platform, they settled on WordPress due to its simplicity and intuitiveness.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-wp-stronk.png"><img width="1024" height="550" src="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-wp-stronk.png" alt="The Jelly Pixel and WP Stronk logos" class="wp-image-54744" style="width:618px;height:auto" /></a></figure>
</div>
<p>The team later branched out to form a second agency,&nbsp;<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a>, which handles subscription-based web maintenance and content entry.</p>
<p>When asked if the agencies focused on any specific niche, Dika said, &#8220;YES! Jelly Pixel is exceptionally skilled at creating illustrative websites with subtle scrolling animations. Our websites leave a lasting impression even after you close the tab.&#8221;</p>
<h2>The impact of WordPress.com</h2>
<p>WordPress.com has been instrumental in helping Jelly Pixel Studio streamline its operations and deliver outstanding services to clients. With a mix of projects in maintenance and those being actively developed, Dika and his team of seven, or “the magnificent seven” as they like to call themselves, have benefited greatly from the platform’s robust features and top-notch performance.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-team-wordpress.png"><img width="1600" height="1192" src="https://en-blog.files.wordpress.com/2024/03/jelly-pixel-team-wordpress.png" alt="The Jelly Pixel Studio team" class="wp-image-54742" /></a></figure>
<p>WordPress developers and agencies are no strangers to the perils and pitfalls of hosting. But WordPress.com solves those problems for Jelly Pixel Studio clients:</p>
<blockquote>
<p>What I love about WordPress.com is its exceptional stability and blazing-fast performance, regardless of your setup. Even with other managed hosting providers, you often need to be mindful of  various settings such as: cache parameters and PHP workers. However, with WordPress.com, <strong>everything just works</strong> seamlessly. <strong>It’s a true “set it and forget it” experience</strong>. </p>
<p>As long as your site is hosted on WordPress.com, you can rest assured that it won’t go down and it won’t slow down, no matter the traffic. I have no idea how you accomplished it, but it’s absolutely AMAZING! </p>
</blockquote>
<h2>Literally magic </h2>
<p>The team considers WordPress.com to be a good fit for their clients. Why?</p>
<blockquote>
<p>You have amazing support, and your infrastructure is <strong>LITERALLY MAGIC</strong>. We have monitored our clients’ uptime, and 100% is a number we often see. How is this even possible? “Amazing” would be an understatement. You have saved me from a ton of urgent calls at night.</p>
</blockquote>
<p>Jelly Pixel Studio believes WordPress.com has one well-kept secret:</p>
<blockquote>
<p>I firmly believe that WordPress.com is the best hosting option for WooCommerce, particularly those with high traffic. </p>
</blockquote>
<p>He thinks this is a missed opportunity for many freelancers and agencies who may not have considered using WordPress.com for their hosting clients. He shares this example:</p>
<blockquote>
<p>I have a client on a different host. They get HUGE traffic. Every time they have a sale, they need to purchase a package upgrade and I have to constantly monitor their ad parameters to ensure proper caching. With the way WordPress.com works, all of this would be seamlessly handled out of the box.</p>
</blockquote>
<p>He adds:</p>
<blockquote>
<p>Unfortunately, the knowledge of WordPress.com as a highly stable WooCommerce hosting solution seems to have been lost over time. It almost feels like a well-kept secret! </p>
</blockquote>
<h2>The verdict</h2>
<p>Dika and his team at Jelly Pixel Studio view WordPress.com as a valuable partner in their web development journey. Dika credits the platform for providing peace of mind, leading to a happier and more productive work environment for his team, as well as clients who no longer complain about their site’s performance. He looks forward to further cooperation with WordPress.com and hopes for the continued evolution of the platform’s capabilities.</p>
<p>At the heart of his work, Dika stands by this quote from Victor Frankl: </p>
<blockquote>
<p>“For success, like happiness, cannot be pursued; it must ensue, and it only does so as the unintended side-effect of one’s personal dedication to a cause greater than oneself.” </p>
</blockquote>
<p>This approach is echoed in the success story of <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a> and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a>, marking the agencies as businesses of kindness, dedication, and commitment to problem-solving.</p>
<h2>The power of hosting with WordPress.com </h2>
<p>WordPress web design and development agencies are discovering <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/hosting/">the power of WordPress.com hosting</a> and the benefits it offers their clients. With <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/site-performance/">full-stack performance</a>, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/platform-features/account-security/">robust security</a>, and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/">developer-friendly features</a>, WordPress.com provides agencies with a platform they can confidently recommend to their clients.</p>
<p>If you&#8217;re<strong> </strong>interested in getting access to the tools and features on WordPress.com that can support your development process, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here to enable our “I am a developer” setting</a> on your WordPress.com account.</p>
<p>Finally, if you&#8217;re in search of an agency specializing in illustrative websites and CRO (Conversion Rate Optimization), <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.jellypixelstudio.com/">Jelly Pixel Studio</a> can help you. For web and content maintenance, check out <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wpstronk.com/">WP Stronk</a> for their comprehensive services.</p>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/case-study-jelly-pixel-studios-journey-with-wordpress-com-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- Wp Fastest Cache: XML Content -->