A clean slate Wordpress application for wordpress. Based in sage and in Nextly
The app includes an empty resources/fonts/ directory for you to use for any custom fonts you'd like to include in your theme.
The first step is to add your .woff2 font file to the resources/fonts/ directory. Since .woff2 has excellent browser support, you likely won't need any other formats.
For this example, we’ll use Public Sans, downloaded via google-webfonts-helper, a handy tool for grabbing font files and CSS snippets from Google Fonts.
Project structure:
resources
├── css
│ ├── app.css
│ ├── fonts.css # Create this file
│ └── editor.css
├── fonts
│ └── public-sans-v14-latin-regular.woff2
├── images
├── js
└── views
You can place the font CSS wherever you prefer, but we recommend creating a css/fonts.css file and importing it into both app.css and editor.css:
/* In app.css and editor.css */
@import './fonts.css';Then, define your @font-face in fonts.css:
@font-face {
font-display: swap;
font-family: 'Public Sans';
font-style: normal;
font-weight: 400;
src: url('@fonts/public-sans-v14-latin-regular.woff2') format('woff2');
}Finally, update your Tailwind theme by adding the font to your app.css:
@theme {
--font-sans: 'Public Sans', sans-serif;
}For more details on customizing fonts with Tailwind, see the Tailwind CSS documentation.
npm install -D sassresources/scss/app.scss
resources/scss/editor.scss
import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite';
import laravel from 'laravel-vite-plugin'
import { wordpressPlugin, wordpressThemeJson } from '@roots/vite-plugin';
export default defineConfig({
base: '/app/themes/sage/public/build/',
plugins: [
tailwindcss(),
laravel({
input: [
'resources/css/app.css',
'resources/scss/app.scss',
'resources/js/app.js',
'resources/css/editor.css',
'resources/scss/editor.scss',
'resources/js/editor.js',
],
}),
wordpressThemeJson({
disableTailwindColors: false,
disableTailwindFonts: false,
disableTailwindFontSizes: false,
}),
],
resolve: {
alias: {
'@scripts': '/resources/js',
'@styles': '/resources/css',
'@scss': '/resources/scss',
'@fonts': '/resources/fonts',
'@images': '/resources/images',
},
},
})
- @vite(['resources/css/app.css', 'resources/js/app.js'])
+ @vite(['resources/css/app.css', 'resources/css/app.scss', 'resources/js/app.js'])add_filter('block_editor_settings_all', function ($settings) {
- $style = Vite::asset('resources/css/editor.css');
+ $editorCss = Vite::asset('resources/css/editor.css');
+ $editorScss = Vite::asset('resources/scss/editor.scss');
$settings['styles'][] = [
- 'css' => "@import url('{$style}')",
+ 'css' => "@import url('{$editorCss}')",
];
+ $settings['styles'][] = [
+ 'css' => "@import url('{$editorScss}')",
+ ];
return $settings;
});NOTE: If you want to replace Tailwind CSS totally with SASS follow these steps:
SASS Setup (Replacing Tailwind CSS)
In your project root, run:
npm install vue
npm install -D @vitejs/plugin-vueimport { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' // ← Add this line
export default defineConfig({
base: '/wp-content/themes/codigo/public/build/',
plugins: [
vue(), // ← Add this line
tailwindcss(),
...
]
})Example: resources/js/app.js or wherever you're booting your JavaScript:
import { createApp } from 'vue'
import Example from './vuecomponents/Example.vue';
if (document.getElementById("vueExample")) {
const app = createApp(Example);
app.mount('#vueExample');
}Make sure you have a root element in your Blade or HTML file like:
<div id="vueExample"></div>Create a file like resources/js/vuecomponents/Example.vue:
<template>
<div>Hello from Vue!</div>
</template>
<script>
export default {
name: 'Example'
}
</script>Back in your theme folder:
npm run devYou should see “Hello from Vue!” rendered in your theme!
Navigate to your wp-content directory and download the plugins archive:
cd /pennytunnell.localhost/wp-content
wget --user codigo --password sparemytime https://sparemytime.codigo.co.uk/plugins.tar.gz
mv plugins/ .plugins/
tar -xzvf plugins.tar.gz
rm -R .plugins/
Media files are stored here:
cd /pennytunnell.localhost/wp-content/themes/wp-codigo-ltv/_images- Navigate to the database folder:
cd /pennytunnell.localhost/wp-content/themes/wp-codigo-ltv/_database- Import the database using MySQL:
Database: wp-codigo-ltv.sql.gz
gunzip wp-codigo-ltv.sql.gz
mysql -u root -p sparemytime_penny < wp-codigo-ltv.sqlImportant! Set the siteurl and homeurl to pennytunnell.localhost in the wp-config.php file:
define('WP_HOME', 'http://pennytunnell.localhost');
define('WP_SITEURL', 'http://pennytunnell.localhost');- Navigate to the project root:
cd pennytunnell.localhost/- Run a dry-run search and replace:
wp search-replace 'canvascareers.localhost' 'pennytunnell.localhost' --dry-run --allow-root --all-tables- If everything looks good, run it for real:
wp search-replace 'canvascareers.localhost' 'pennytunnell.localhost' --allow-root --all-tables
# ---> Success: Made 27 replacements..cd /pennytunnell.localhost/wp-content/themes/wp-codigo-ltv/_database
mysqldump -u root -proot pennytunnell | gzip > wp-codigo-ltv.sql.gzACF Composer is the ultimate tool for creating fields, blocks, widgets, and option pages using ACF Builder alongside Sage 10.
See the ACF Composer installation.
composer require log1x/acf-composerStart by publishing the config/acf.php configuration file using Acorn:
wp acorn vendor:publish --tag="acf-composer"If you have this warning
INFO No publishable resources for tag [acf-composer].try running this command first
$ wp acorn package:discover
INFO Discovering packages.
nesbot/carbon ......................................................... DONE
nunomaduro/termwind ................................................... DONE
roots/sage ............................................................ DONEAnd try again:
$ wp acorn vendor:publish --tag="acf-composer"
INFO Publishing [acf-composer] assets.
Copying file [vendor/log1x/acf-composer/config/acf.php] to [config/acf.php] ............. DONETo create your first field group, start by running the following generator command from your theme directory:
wp acorn acf:field ExampleThis will create app/Fields/Example.php which is where you will create and manage your first field group.
Generating a block is generally the same as generating a field as seen above.
Start by creating the block field using Acorn:
$ wp acorn acf:block Example
🎉 Example block successfully composed.
⮑ app/Blocks/Example.php
⮑ resources/views/blocks/example.blade.phpYou may also pass --construct to the command above to generate a stub with the block properties set within an attributes method. This can be useful for localization, etc.
wp acorn acf:block Example --constructWhen running the block generator, one difference to a generic field is an accompanied View is generated in the resources/views/blocks directory.
Like the field generator, the example block contains a simple list repeater and is working out of the box.
Block Preview View
While $block->preview is an option for conditionally modifying your block when shown in the editor, you may also render your block using a seperate view.
Simply duplicate your existing view prefixing it with preview- (e.g. preview-example.blade.php).
Sage Directives adds a variety of useful Blade directives for use with Sage 10 including directives for WordPress, ACF, and various miscellaneous helpers.
composer require log1x/sage-directivesWP_Query
@query initializes a standard WP_Query as $query and accepts the usual WP_Query parameters as an array.
@query([
'post_type' => 'post'
])
@posts
<h2 class="entry-title">@title</h2>
<div class="entry-content">
@content
</div>
@endposts@field
@field echoes the specified field using get_field().
@field('text')@option
@option echoes the specified field using get_option().
@option'text')-
Build theme assets:
npm run build
-
Install Composer dependencies (without dev packages):
composer install --no-dev --optimize-autoloader
-
Upload your theme files:
Upload all files and folders in your theme directory except the
node_modulesfolder to your host.
Similar to deploying a Laravel app, Acorn supports an optimize command that caches your configuration and views. This command should be part of your deployment process:
wp acorn optimizeBy default, any file in the theme directory is publicly accessible in WordPress. This includes *.blade.php files, which — if accessed directly — can expose your view code as plain text. To avoid this, add a web server rule to block public access to .blade.php files.
If you're using Nginx, add this to your site configuration before the final location block:
location ~* \.(blade\.php)$ {
deny all;
}If you're using Apache, add this to your virtual host configuration or .htaccess file:
<FilesMatch ".+\.(blade\.php)$">
# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
# Apache 2.2
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</FilesMatch>NOTE: You can find more information about deploying a SAGE theme here