L
L
lavezzi12017-07-30 05:52:10
WordPress
lavezzi1, 2017-07-30 05:52:10

How to extract id from url?

For a custom router, you need a function to pull parameters from the url. Works like this:

localhost:3000 - index page
localhost:3000/#items - item page
localhost:3000/#items/10/index - item id 10

Here's how to pull this parameter? And how can you flexibly make it possible to pull out from different positions? (at the end, at the beginning).

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
Petr Volkhanov, 2019-03-05
@mgis

The Yoast SEO Woocommerce plugin solves the problem

S
Sergey, 2021-05-16
@kurul86

Good day.
I read your question, but before that I "rummaged through the entire space of the Internet" and unfortunately nothing came of it (((
But ...
When I clearly began to delve into the essence, I realized one thing that the Google console gives an error on the pages of product categories and tags (tags) of the product.
That is, Google sees these pages as a separate product and, accordingly, there is no price, no reviews, in short, nothing from what is needed for the product page.
I installed the Rank Math SEO plugin and in the metadata settings there is under the settings for product categories and product tags, and there is a checkbox "Delete data from snippet (Delete schema markup data from Category (Label))" and everything worked fine.
I'm not a coder, just the owner of an online store, I don't know where and what and how to prescribe. This method helped me and I hope it will help someone else.

A
Alexander Ponomarev, 2017-07-30
@Twoogi

If I understand correctly, then you can

var link = 'localhost:3000/#items/10/index';
var arr = link.split('/');
console.log(arr[2]); //10

A
Alexander Petrov, 2017-07-30
@Mirkom63

judging by localhost:3000, so I understand you have ruby? but if not, then anyway ..
in the general backend, pull out the value and insert it into the input in the header of the type template
like this:
And then with the help of js you take the value: The option is probably clumsy .... but I think it should work) And if it's pure js, then as the option above. It is necessary to take the value of the address bar and decompose it into an array or take it through regular expressions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question