Wordpress custom theme
The information in this post is accurate as of the published date . Please make sure to check any linked documentation within the post for changes/updates.
Hi,
I have followed this post to install my custom theme: https://support.platform.sh/hc/en-us/community/posts/16439636140306-How-to-install-custom-private-Wordpress-plugins-and-themes-with-Composer?input_string=Wordpress%20custom%20theme
My custom theme is in /themes/my-theme.
My problem is that I need to run "platform build" every time I make a change in my code to copy my theme files to the /wordpress/wp-content/themes/my-theme directory.
This is absolutely not convenient and I guess there is a better way, or I did not understand how Wordpress works on Platform.sh.
Thank you
-
Hi @maxime - how would you normally handle this? As I understand the point of the post, its an attempt to leverage composer to keep custom plugins and themes in the same repository, and that this is the way WordPress recommends you do so (continuing to manage WordPress with composer as Platform.sh recommends). Curious to how you are used to working with this.
0 -
Hi Chad, my problem only concerns the way I develop a WP website locally within the environment and structure required by Platform.
My theme files are located in a directory at the project root (/) which must be copied to the /wordpress directory so I can view the changes when checking the website locally in the browser. From what I understood, this copy task is done by running “platform build” but it is a manual task. I don't want to run this every time I make a change in my theme code.
Have you succeeded to develop a WP website smoothly on Platform?
0 -
@maxime, there are a couple of ways you can handle this depending on how you prefer to work.
If your theme is in a repository all its own, you can add it as a dependency to your composer.json file. In your theme's composer.json meta file, make sure to mark the package as
type: wordpress-theme
. Then as you make changes and updates, you can runcomposer update <yournamespace>/<yourtheme>
to bring in the latest version and have it copied into the correct location.If it isn't in a repository of its own, but in the repository with the rest of your project, you can define your theme as a local package in your project's composer.json:
"repositories": [ { "type": "path", "url": "/full/or/relative/path/to/your/theme" } ] Docs are here: https://getcomposer.org/doc/05-repositories.md#path
of course, this will still require that you run
composer update
after you make changes, which can still be a bit of a pain.ANOTHER option to get around having to run the `update` command when developing locally is to instead create a symlink between the theme's directory and where it needs to be in your project. if your theme files are in
themes/<your-theme>
in the root of your repository, and they need to eventually be inwordpress/wp-content/themes/my-theme
then you could symlink:
ln -s -f /path/to/your/project/themes/mytheme /path/to/your/project/wordpress/wp-content/themes
You can even replace the copying of your theme into the wordpress theme location in the build hook with a symlink:
hooks: # The build hook runs after Composer to finish preparing up your code. # No services are available but the disk is writeable. build: | ln -s -f “${PLATFORM_APP_DIR}/themes/mytheme” “${PLATFORM_APP_DIR}/wordpress/wp-content/themes”
Yet another option would be to have your IDE watch for changes in your theme's directory and upon saving the change, copy it into the wp-content/themes directory for you. The specifics of setting that up will depend on which IDE you are using.
Let me know if this helps answer your question. If not, if you can provide us with some more information (IDE in use, project set up, describe your ideal workflow, etc) I'm sure we can come up with a solution.
0
Please sign in to leave a comment.
Comments
3 comments