<?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; JS</title>
	<atom:link href="https://foodbloggermania.it/tag/ricette/js/feed/" rel="self" type="application/rss+xml" />
	<link>https://foodbloggermania.it</link>
	<description>Food Blogger Mania</description>
	<lastBuildDate>Thu, 09 Apr 2026 04:13:07 +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>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>Ragazze conTorte</dc:creator>
				<category><![CDATA[Lazio]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[FSE]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme Name]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/site-editor/">Full Site Editing</a> (FSE) because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use FSE as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and FSE templates from both custom code and our parent Twenty Twenty-Four theme. The FSE templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-FSE templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the FSE styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the FSE page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the FSE header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>The new developer.wordpress.com site is now live!</h2>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-2/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-2/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>Pani cunzatu</dc:creator>
				<category><![CDATA[Sicilia]]></category>
		<category><![CDATA[Author Automattic Author]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[FSE]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-2/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-2/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/site-editor/">Full Site Editing</a> (FSE) because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use FSE as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and FSE templates from both custom code and our parent Twenty Twenty-Four theme. The FSE templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-FSE templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the FSE styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the FSE page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the FSE header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>The new developer.wordpress.com site is now live!</h2>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-3/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-3/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>Alveare Delle Delizie</dc:creator>
				<category><![CDATA[Friuli Venezia Giulia]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[FSE]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-3/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-3/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/support/site-editor/">Full Site Editing</a> (FSE) because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use FSE as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and FSE templates from both custom code and our parent Twenty Twenty-Four theme. The FSE templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-FSE templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the FSE styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the FSE page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the FSE header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>The new developer.wordpress.com site is now live!</h2>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://www.developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-4/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-4/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>BucciaDiArancia</dc:creator>
				<category><![CDATA[Piemonte]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site Editor]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-4/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.&#160; Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-4/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more.&nbsp;</p>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/updates/2022/11/04/site-editor-a-more-user-friendly-name/">the Site Editor</a> because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use the Site Editor as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and Site Editor templates from both custom code and our parent Twenty Twenty-Four theme. The Site Editor templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-Site Editor templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the Site Editor styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the Site Editor page templates are kept in code with version control. </p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the Site Editor header template. </p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>Our new home for developers is now live!</h2>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback. </p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-5/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-5/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>claudialuca90</dc:creator>
				<category><![CDATA[Sicilia]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site Editor]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-5/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-5/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<div>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/updates/2022/11/04/site-editor-a-more-user-friendly-name/">the Site Editor</a> because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use the Site Editor as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and Site Editor templates from both custom code and our parent Twenty Twenty-Four theme. The Site Editor templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-Site Editor templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the Site Editor styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the Site Editor page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the Site Editor header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>Our new home for developers is now live!</h2>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-6/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-6/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>Gemma archeologa tra i fornelli.</dc:creator>
				<category><![CDATA[Toscana]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site Editor]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-6/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-6/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<div>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/updates/2022/11/04/site-editor-a-more-user-friendly-name/">the Site Editor</a> because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use the Site Editor as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and Site Editor templates from both custom code and our parent Twenty Twenty-Four theme. The Site Editor templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-Site Editor templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the Site Editor styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the Site Editor page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the Site Editor header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>Our new home for developers is now live!</h2>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-7/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-7/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>santox89</dc:creator>
				<category><![CDATA[Campania]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site Editor]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-7/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-7/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<div>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/updates/2022/11/04/site-editor-a-more-user-friendly-name/">the Site Editor</a> because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use the Site Editor as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and Site Editor templates from both custom code and our parent Twenty Twenty-Four theme. The Site Editor templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-Site Editor templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the Site Editor styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the Site Editor page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the Site Editor header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>Our new home for developers is now live!</h2>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-8/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-8/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>Ovosodo Cook</dc:creator>
				<category><![CDATA[Emilia Romagna]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site Editor]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-8/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-8/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<div>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/updates/2022/11/04/site-editor-a-more-user-friendly-name/">the Site Editor</a> because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use the Site Editor as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and Site Editor templates from both custom code and our parent Twenty Twenty-Four theme. The Site Editor templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-Site Editor templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the Site Editor styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the Site Editor page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the Site Editor header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>Our new home for developers is now live!</h2>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-9/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-9/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>Mariapia</dc:creator>
				<category><![CDATA[Basilicata]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site Editor]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-9/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-9/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<div>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/updates/2022/11/04/site-editor-a-more-user-friendly-name/">the Site Editor</a> because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use the Site Editor as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and Site Editor templates from both custom code and our parent Twenty Twenty-Four theme. The Site Editor templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-Site Editor templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the Site Editor styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the Site Editor page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the Site Editor header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>Our new home for developers is now live!</h2>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-10/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-10/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>fucinaidee</dc:creator>
				<category><![CDATA[Veneto]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site Editor]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-10/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-10/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<div>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/updates/2022/11/04/site-editor-a-more-user-friendly-name/">the Site Editor</a> because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use the Site Editor as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and Site Editor templates from both custom code and our parent Twenty Twenty-Four theme. The Site Editor templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-Site Editor templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the Site Editor styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the Site Editor page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the Site Editor header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>Our new home for developers is now live!</h2>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How We Built a New Home for WordPress.com Developers Using the Twenty Twenty-Four Theme</title>
		<link>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-11/</link>
		<comments>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-11/#comments</comments>
		<pubDate>Thu, 29 Feb 2024 20:55:03 +0000</pubDate>
		<dc:creator>ricette da coinquiline</dc:creator>
				<category><![CDATA[Campania]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site Editor]]></category>
		<category><![CDATA[Twenty Twenty]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-11/</guid>
		<description><![CDATA[In the last few weeks, our team here at WordPress.com has rebuilt developer.wordpress.com from the ground up. If you build or design websites for other people, in any capacity, bookmark this site. It’s your new home for docs, resources, the latest news about developer features, and more.  Rather than creating a unique, custom theme, we&#160;<a href="https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-11/" class="read-more">Continua a leggere..</a>]]></description>
			<content:encoded><![CDATA[<p>In the last few weeks, our team here at WordPress.com has rebuilt <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> from the ground up. <strong>If you build or design websites for other people, in any capacity, bookmark this site</strong>. It’s your new home for docs, resources, the latest news about developer features, and more. </p>
<div>
<figure><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com"><img width="1600" height="1170" src="https://en-blog.files.wordpress.com/2024/02/new-developer-wordpress-com.png" alt="The new developer.wordpress.com homepage with a black background, a pixelated W logo, and the headline 'Powerful WordPress Hosting for Developers'" class="wp-image-54681" /></a></figure>
</div>
<p>Rather than creating a unique, custom theme, we went all-in on using <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/theme/twentytwentyfour">Twenty Twenty-Four</a>, which is the default theme for all WordPress sites.&nbsp;</p>
<p>That’s right, with a combination of built-in Site Editor functionalities and traditional PHP templates, we were able to create a site from scratch to house all of our developer resources.&nbsp;</p>
<p>Below, I outline exactly how our team did it.</p>
<h2>A Twenty Twenty-Four Child Theme</h2>
<p>The <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site has existed for years, but we realized that it needed an overhaul in order to modernize the look and feel of the site with our current branding, as well as accommodate <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">our new developer documentation</a>.&nbsp;</p>
<p>You’ll probably agree that the site needed a refresh; here’s what <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> looked like two weeks ago:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png"><img width="1600" height="1010" src="https://en-blog.files.wordpress.com/2024/02/old-developer-wordpress-com-homepage.png" alt="The old developer.wordpress.com homepage with the headline 'Howdy, Developers' on a blue background with several CTAs to get started and try WordPress.com for free" class="wp-image-54651" /></a></figure>
</div>
<p>Once we decided to redesign and rebuild the site, we had two options: 1) build it entirely from scratch or 2) use an existing theme.&nbsp;</p>
<p>We knew we wanted to use <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://make.wordpress.org/updates/2022/11/04/site-editor-a-more-user-friendly-name/">the Site Editor</a> because it would allow us to easily use <strong>existing patterns</strong> and give our content team the <strong>best writing and editing experience </strong>without them having to commit code.</p>
<p>We considered starting from scratch and using the<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/plugins/create-block-theme/"> official “Create Block Theme” plugin</a>. Building a new theme from scratch is a great option if you need something tailored to your specific needs, but Twenty Twenty-Four was already close to what we wanted, and it would give us a headstart because we can inherit most styles, templates, and code from the parent theme.</p>
<p>We quickly decided on a hybrid theme approach: we would use the Site Editor as much as possible but still fall back to CSS and classic PHP templates where needed (like for our Docs custom post type).</p>
<p>With this in mind, we created a minimal child theme based on Twenty Twenty-Four.</p>
<h3>Spin up a scaffold with <code>@wordpress/create-block</code></h3>
<p>We initialized our new theme by running <code>npx @wordpress/create-block@latest wpcom-developer</code>.&nbsp;</p>
<p>This gave us a folder with example code, build scripts, and a plugin that would load a custom block.</p>
<p>If you only need a custom block (not a theme), you’re all set.</p>
<p><em>But we’re building a theme here! </em>Let’s work on that next.</p>
<h3>Modify the setup into a child theme</h3>
<p>First, we deleted&nbsp;<code>wpcom-developer.php</code>, the file responsible for loading our block via a plugin. We also added a <code>functions.php</code> file and a&nbsp;<code>style.css</code> file <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/child-themes/">with the expected syntax required</a> to identify this as a child theme.&nbsp;</p>
<p>Despite being a CSS file, we’re not adding any styles to the <code>style.css</code>&nbsp;file. Instead, you can think of it <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/core-concepts/main-stylesheet/#file-header">like a documentation file</a> where <code>Template: twentytwentyfour</code> specifies that the new theme we’re creating is a child theme of Twenty Twenty-Four.</p>
<div>
<pre>
/*
Theme Name: wpcom-developer
Theme URI: https://developer.wordpress.com
Description: Twenty Twenty-Four Child theme for Developer.WordPress.com
Author: Automattic
Author URI: https://automattic.com
Template: twentytwentyfour
Version: 1.0.0
*/
</pre>
</div>
<p>We removed all of the demo files in the “src” folder and added two folders inside: one for CSS and one for JS, each containing an empty file that will be the entry point for building our code.</p>
<p>The theme folder structure now looked like this:</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png"><img width="665" height="471" src="https://en-blog.files.wordpress.com/2024/02/child-theme-folder-structure-wordpress.png" alt="A WordPress child theme folder structure" class="wp-image-54658" /></a></figure>
</div>
<p>The build scripts in <code>@wordpress/create-block</code> can build SCSS/CSS and TS/JS out of the box. It uses Webpack behind the scenes and provides a standard configuration. We can extend the default configuration further with custom entry points and plugins by adding our own <code>webpack.config.js</code> file.&nbsp;</p>
<p>By doing this, we can:</p>
<ol>
<li><strong>Build specific output files for certain sections of the site</strong>. In our case, we have both PHP templates and Site Editor templates from both custom code and our parent Twenty Twenty-Four theme. The Site Editor templates need minimal (if any) custom styling (thanks to <code>theme.json</code>), but our developer documentation area of the site uses a custom post type and page templates that require CSS.</li>
<li><strong>Remove empty JS files</strong> after building the <code>*.asset.php</code> files. Without this, an empty JS file will be generated for each CSS file.</li>
</ol>
<p><a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/advanced-topics/build-process/#configuring-webpack">Since the build process in WordPress Scripts relies on Webpack</a>, we have complete control over how we want to modify or extend the build process.&nbsp;</p>
<p>Next, we installed the required packages:</p>
<div>
<pre>
​​npm install path webpack-remove-empty-scripts --save-dev
</pre>
</div>
<p>Our <code>webpack.config.js</code> ended up looking similar to the code below. Notice that we’re simply extending the <code>defaultConfig</code> with a few extra properties.</p>
<p>Any additional entry points, in our case <code>src/docs</code>, can be added as a separate entry in the <code>entry</code> object.</p>
<div>
<pre>
// WordPress webpack config.
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

// Plugins.
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );

// Utilities.
const path = require( 'path' );

// Add any new entry points by extending the webpack config.
module.exports = {
	...defaultConfig,
	...{
		entry: {
			'css/global':  path.resolve( process.cwd(), 'src/css',   'global.scss' ),
			'js/index': path.resolve( process.cwd(), 'src/js', 'index.js' ),
		},
		plugins: &#091;
			// Include WP's plugin config.
			...defaultConfig.plugins,
			// Removes the empty `.js` files generated by webpack but
			// sets it after WP has generated its `*.asset.php` file.
			new RemoveEmptyScriptsPlugin( {
				stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
			} )
		]
	}
};
</pre>
</div>
<p>In <code>functions.php</code>, we enqueue our built assets and files depending on specific conditions. For example,&nbsp;we built separate CSS files <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">for the docs area of the site</a>, and we only enqueued those CSS files for our docs.&nbsp;</p>
<div>
<pre>
&lt;?php

function wpcom_developer_enqueue_styles() : void {
    wp_enqueue_style( 'wpcom-developer-style',
        get_stylesheet_directory_uri() . '/build/css/global.css'
    );
}

add_action( 'wp_enqueue_scripts', 'wpcom_developer_enqueue_styles' );
</pre>
</div>
<p>We didn&#8217;t need to register the style files from Twenty Twenty-Four, as WordPress handles these inline.</p>
<p>We <em>did</em> need to enqueue the styles for our classic, non-Site Editor templates (in the case of our <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/">developer docs</a>) or any additional styles we wanted to add on top of the Site Editor styles.</p>
<p>To build the production JS and CSS locally, we run <code>npm run build</code>.&nbsp;</p>
<p>For local development, you can run <code>npm run start</code> in one terminal window and <code>npx wp-env start</code> (<a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/">using the wp-env package</a>) in another to start a local WordPress development server running your theme.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png"><img width="768" height="622" src="https://en-blog.files.wordpress.com/2024/02/active-child-theme-wordpress.png" alt="An active wpcom-developer child theme on a local WordPress installation" class="wp-image-54668" style="width:726px;height:auto" /></a></figure>
</div>
<p>While building this site, our team of designers, developers, and content writers used <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com/docs/developer-tools/staging-sites/">a WordPress.com staging site</a> so that changes did not affect the existing <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site until we were ready to launch this new theme.</p>
<h2><code>theme.json</code></h2>
<p>Twenty Twenty-Four has a comprehensive <code>theme.json</code> file that defines its styles. By default, our hybrid theme inherits all of the style definitions from the parent (Twenty Twenty-Four) <code>theme.json</code> file.&nbsp;</p>
<p>We selectively overwrote the parts we wanted to change (the color palette, fonts, and other brand elements), leaving the rest to be loaded from the parent theme.&nbsp;</p>
<p>WordPress handles this merging, as well as any changes you make in the editor.&nbsp;</p>
<p>Many of the default styles worked well for us, and we ended up with a compact <code>theme.json</code> file that defines colors, fonts, and gradients. Having <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://core.trac.wordpress.org/browser/branches/6.4/src/wp-content/themes/twentytwentyfour/theme.json">a copy of the parent theme’s</a> <code>theme.json</code> file makes it easier to see how colors are referenced.</p>
<p>You can change <code>theme.json</code> in your favorite code editor, or you can change it directly in the WordPress editor and <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.org/documentation/article/site-editor/#how-to-export-templates-and-styles">then download the theme files from Gutenberg</a>.</p>
<div>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png"><img width="1008" height="1340" src="https://en-blog.files.wordpress.com/2024/02/wordpress-toolbar.png" alt="WordPress settings with a red arrow pointing to the Export tool" class="wp-image-54672" style="width:555px;height:auto" /></a></figure>
</div>
<p>Why might you want to export your editor changes? Styles can then be transferred back to code to ensure they match and make it easier to distribute your theme or move it from a local development site to a live site. This ensures the Site Editor page templates are kept in code with version control.&nbsp;</p>
<p>When we launched this new theme on production, the template files loaded from our theme directory; we didn&#8217;t need to import database records containing the template syntax or global styles.</p>
<h3>Global styles in SCSS/CSS</h3>
<p>Global styles are added as CSS variables, and they can be referenced in CSS. Changing the value in <code>theme.json</code> will also <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.org/themes/global-settings-and-styles/settings/color/#registering-custom-color-presets">ensure that the other colors are updated</a>.</p>
<p>For example, here’s how we reference our “contrast” color as a border color:</p>
<div>
<pre>
border-color: var(--wp--preset--color--contrast);
</pre>
</div>
<h2>What about <code>header.php</code> and <code>footer.php</code>?</h2>
<p>Some plugins require these files in a theme, e.g. by calling <code>get_header()</code>, which does not automatically load the Site Editor header template.&nbsp;</p>
<p>We did not want to recreate our header and footer to cover those cases; having just one source of truth is a lot better.</p>
<p>By using <code>do_blocks()</code>, we were able to render our needed header block. Here’s an example from a header template file:</p>
<div>
<pre>
&lt;head&gt;
&lt;?php
wp_head();
$fse_header_block = do_blocks( '&lt;!-- wp:template-part {&quot;slug&quot;:&quot;header&quot;,&quot;theme&quot;:&quot;a8c/wpcom-developer&quot;,&quot;tagName&quot;:&quot;header&quot;,&quot;area&quot;:&quot;header&quot;, &quot;className&quot;:&quot;header-legacy&quot;} /--&gt;' );
?&gt;
&lt;/head&gt;
&lt;body &lt;?php body_class(); ?&gt;&gt;
&lt;?php
echo $fse_header_block;
</pre>
</div>
<h2>Our new home for developers is now live!</h2>
<p>Check out our new-and-improved <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://developer.wordpress.com">developer.wordpress.com</a> site today, and leave a comment below telling us what you think. We’d love your feedback.&nbsp;</p>
<p>Using custom code and staging sites are just two of the many developer features available to WordPress.com sites that we used to build our new and improved developer.wordpress.com.</p>
<p>If you’re a developer and interested in getting early access to other development-related features, <a target="_blank" rel="nofollow" href="/redirect.php?URL=https://wordpress.com/me/developer">click here</a> to enable our “I am a developer” setting on your WordPress.com account.</p>
<figure><a target="_blank" rel="nofollow" href="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png"><img width="1600" height="1038" src="https://en-blog.files.wordpress.com/2024/02/developer-features-wordpress.png" alt="the Developer Features page on WordPress.com with an &quot;I am a developer&quot; toggle and cards displaying developer features like SFTP, SSH, WP-CLI, Staging sites, and Custom code" class="wp-image-54676" /></a></figure>
]]></content:encoded>
			<wfw:commentRss>https://foodbloggermania.it/ricetta/how-we-built-a-new-home-for-wordpress-com-developers-using-the-twenty-twenty-four-theme-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- Wp Fastest Cache: XML Content -->