Wp-source: no option to change archive URL

I can’t find an option to change the URL of archives.

In my project I have:

  postsPage: '/blog',
  categoryBase: 'blog/category',
  authorBase: 'blog/author',
  tagBase: 'blog/tag',

All posts/categories are correctly prefixed by blog slug except archives by year/month.

It should be https://domain.com/blog/2021/05
but it is: https://domain.com/2021/05

On the backend archives are served from the correct URL with blog slug.

How can I force Frontity to use this slug for archives?

Here is the config from Wordpress admin

Response for /blog/2021/05/:

Screen Shot 2021-06-03 at 8.55.01 AM

And for /2021/05/:
Screen Shot 2021-06-03 at 8.55.40 AM

Hi @marek

Can you please provide a repo or code-sandbox with your code? This is especially helpful to find solutions to technical issues with specific code

Detailing the info suggested here when having issues will help the community to provide the best possible help as quickly and as efficiently as possible.

Hi @juanma .

I was able to replicate this issue on clean WP and Frontity install (Mars Theme).

Here is the repository with Frontity:

I only added this:

      homepage: '/home',
      postsPage: '/blog',
      categoryBase: 'blog/category',
      authorBase: 'blog/author',
      tagBase: 'blog/tag',

to the frontity.settings.js file.

It’s connected to the fresh instance of Wordpress at https://distcode.uk/frontity-blog.

You can login there using:
User: frontity
Password: frontity

@David, can you help here?

In this codesandbox

you can see how these settings in frontity.settings.js

  {
      name: "@frontity/wp-source",
      state: {
        source: {
          url: "https://distcode.uk/frontity-blog",
          homepage: "/home",
          postsPage: "/blog",
          categoryBase: "blog/category",
          authorBase: "blog/author",
          tagBase: "blog/tag"
        }
      }
    },

and these ones on the WordPress side

Captura de pantalla 2021-06-04 a las 8.49.05

make all links in the Top Menu work but the one with the text “Prefixed archive 2021/02”

Any thoughts?

Hey @marek :wave:

Currently there isn’t an option in the wp-source package to change the URL pattern of date archives.

However, you can add the following init() action in your theme to create a new handler for your date archives starting with /blog:

      init: ({ libraries }) => {
        // Search the default handler for date archives.
        const dateHandler = libraries.source.handlers.find(
          ({ name }) => name === "date"
        );

        // Create a new one prepending "/blog" to the pattern and giving it
        // more priority.
        libraries.source.handlers.push({
          name: "date (blog)",
          pattern: `/blog${dateHandler.pattern}`,
          priority: dateHandler.priority - 1,
          func: dateHandler.func,
        });
      },

Hope it helps!

Hi @David,
thank you for your reply!

I tried to add it in the starter theme to marsTheme.actions.theme.init but libraries.source.handlers returns empty array there so the script fails as it can’t find the correct handler.

I tried it in my project too, but only custom handlers provided by my theme or by packages (like @frontity/wp-comments) are available there.

Where should I add it then?

Oh, right. That happens because packages in frontity.settings.js are evaluated in the same order they are defined, so your mars-theme package should appear before @frontity/wp-source. Try moving @frontity/wp-source to the first place. That way, when the init() action of mars-theme runs, libraries.source.handlers should be defined.

BTW, that’s something we wanted to fix with the Frontity Priorities API, but we haven’t started to work on that yet.

1 Like