504 error is likely a server related issue. Therefore, ask your host why the 504 is occurring.
Your error_log file may also explain it. So please check the error logs on your server. If you need help locating them, ask your hosting provider to help you with that.
Meanwhile try:
– If you have access to your Dashboard’s Plugins page, try deactivating ALL (yes all) plugins temporarily to see if this resolves the problem (plugin functions can interfere). If this works, re-activate them individually (one-by-one) to find the problematic plugin(s).
– If you don’t have access to your Dashboard’s Plugins page, try manually resetting your plugins (no Dashboard access required). Here is another tutorial: https://www.wpbeginner.com/plugins/how-to-deactivate-all-plugins-when-not-able-to-access-wp-admin/ . If that resolves the issue, reactivate each one individually until you find the cause. Also remember to deactivate any plugins in the mu-plugins folder (if you have created such folder). The easiest way is to rename that folder to mu-plugins-old.
– switching to the unedited default Theme (Twenty Twenty, etc.) for a moment using the WP dashboard to rule out any theme-specific issue (theme functions can interfere like plugins).
If you don’t have access to your Dashboard’s Appearance page, access your server via SFTP or FTP, or a file manager in your hosting account’s control panel (consult your hosting provider’s documentation for specifics on these), navigate to /wp-content/themes/ and rename the directory of your currently active theme. Alternately, you can remove other themes except the default theme (Twenty Twenty, etc.). That will force your site to use it.