What Wordpress PHP Theme should I use with Frontity?

Hi,

Maybe a dumb question but could not find any info on this, what theme should I activate on the WP dashboard (even though it doesn’t render this) and how to hide it from the public?

You can use something like Nude:

We haven’t released it yet, but our PHP plugin will be capable of overwriting your theme and you will have some options, like:

2 Likes

Perfect thanks for the info.

I was thinking of doing something like this

<script type="text/javascript">
  window.location = 'https://my-site.com';
</script>

but I was wondering what best practice stipulates when using WP headless.
Security and SEO wise what would be the best option if a user hits your API homepage?

PS looking to contribute to this project in the new year.

I think the safer option is probably a 301 redirection. I’m going to ask our SEO expert and I’ll get back to you.

Awesome! Let us know and we’ll help you get onboard :smile:

Hi @b-bot ! The best approach SEO-wise is indeed what @luisherranz commented: doing a 301 redirect from any URL from the API site to the public site where Frontity is installed, except any URL that starts with “/wp-json” (as that’s what Frontity needs in order to get the content of your site).

You should redirect each URL to the corresponding URL on the Frontity site (so, homepage to homepage, post to post, category to category, etc.)

Ideally you should do this creating a rule on the .htaccess file on the API server so Googlebot won’t depend on rendering the page and executing JS to see the redirect.

Hope that helps!

1 Like

Hmm… maybe we can provide:

  • The .htaccess rule.
  • The Nginx rule.
  • A regexp string people can add to a WP redirection plugin (like this one, this one or this one).

@christianoliveira do you know how to do this with .htaccess? I can look for Nginx and WP plugins.

Sure!

The following lines would do the trick included on the .htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule !^(wp-json|wp-admin|wp-login\.php|wp-includes|wp-content|wp-comments-post\.php|wp-cron\.php|wp-trackback\.php|wp-signup\.php|xmlrpc\.php)(\/|$) http://domain.com%{REQUEST_URI} [L,R=301]
</IfModule>

A similar thing can be achieved with this plugin: https://wordpress.org/plugins/simple-website-redirect/ , configuring it like this:

Exclude Paths:

/wp-json,/wp-includes,/wp-content,/wp-comments-post.php,/wp-cron.php,/wp-trackback.php,/wp-signup.php,/xmlrpc.php,/index.php

Exclude Query Parameters:

preview

Note that this plugin adds exceptions by default to some of Wordpress’ URLs like /wp-admin or /wp-login.php

Depending on the specific setup, there may be some variations. For example, if your API site is configured in wp.domain.com/blog/ you may need to specify /blog/wp-json on the “Exclude Paths” section.

2 Likes

Hey, I didn’t know Micah Wood had a redirection plugin. It looks really neat, thanks Chris :slight_smile:

@christianoliveira thank you for the detailed explanation, I usually want to know why something is better than an alternative and you nailed it :smiley: The plugin may indeed be better if it’s a PHP based redirect because .htaccess propagation can be time-intensive.

I am trying out something a little more complex though, I have Frontity on a subdomain (blog) and the WP installation on another (cms) with a Next.js project running on the primary - How would I go about having a route /blog point to frontity across two installations? And how does that affect the redirects?

PS Node stuff is on Now and WP is on AWS Lightsail.

@luisherranz I will be using the above project as a testbed for various plugin ideas I have for Frontity. Just want to get this setup and I can start contributing. :man_technologist:t3:

Already saved this forum as a Chrome App :stuck_out_tongue:

@b-bot no worries, that’s why I am here!

Could you be more specific about your setup? If I’m understanding correctly, you have:

And you want the blog to be accesible by end users at domain.com/blog/, is that correct?

It will work as long as you put the Frontity project inside the /blog folder and add this now.json file to the root:

{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@now/next"
    },
    {
      "src": "blog/package.json",
      "use": "@frontity/now"
    }
  ]
}

I’ve created a the repo example: https://next-and-frontity.luisherranz.now.sh/
And this is the deploy: https://next-and-frontity.luisherranz.now.sh/

@christianoliveira This is correct, I don’t think the blog on the subdomain is necessary anymore because @luisherranz solution worked perfectly. I actually didn’t know Next would create a route when adding a folder to root and not in the pages directory.

So then I suppose my final question would be what to do with SEO and configuration in this particular setup?

@b-bot You would have, then:

The redirects that you need to setup are exactly the same as described above, but using domain.com/blog/ as the destination instead of domain.com (if you use the plugin, you have to define http://domain.com/blog/ as the “Redirect URL”). Let us know if it works!

I think it’s also a good idea to add preview at Exclude Query Parameters, if not previews won’t work as usual.

1 Like

There is another interesting plugin to deactivate the WordPress theme and do redirections: https://wordpress.org/plugins/wp-headless/

I wonder if anyone gave it a try :slightly_smiling_face:

Sorry about the delay on this - life has been crazy the past 2 months.

@christianoliveira I have configured that plugin however whenever saving the settings it wipes the domain field and says “Settings saved”. Not sure if this is because it’s on a subdomain?
I also wanted to ask regarding the REST API - Head Tags plugin, I know it ties in with Yoast however I had set it to not index my site while waiting for the redirect to be completed. Does this mean this won’t be visible to Frontity or does Yoast still serve the meta through the API?

@luisherranz is the team perhaps working on a plugin like Nude that enables redirects? Your plugins are so well made I would prefer that.

Yes, indeed.

We are about to start working on the main Frontity PHP plugin, which will let you choose between different options for this, including 301 redirects to the Frontity site.

EDIT: It’s still going to take a while until we start with the PHP plugin, but:

/**
 * Do 301 redirections for any front-end URL that is not a preview.
*/
function frontity_frontend_redirects() {
  // Only redirect if home_url and site_url are different, to avoid infinite
  // redirection loops.
  if ( home_url() !== site_url() && ( !is_user_logged_in() || !is_preview() ) ) {
    wp_redirect( home_url( $_SERVER['REQUEST_URI'] ), 301 );
      die;
  }
}
add_action( 'template_redirect', 'frontity_frontend_redirects', PHP_INT_MAX );

You should also set home_url to the URL of Frontity:

1 Like

You might also want to take a look at this plugin (thanks to @403page for the heads-up :slightly_smiling_face:)

2 Likes