Skip to main content

Wordpress custom theme

Comments

3 comments

  • Chad Carlson

    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
  • maxime

    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
  • Paul Gilzow

    @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 run composer 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 in wordpress/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.