It appears Google has somehow managed to crawl and index the /user/password page (according to Google Search Console) - is it possible to set it to "noindex" (without using Node noindex)?
Accepted answer
Most helpful answers
I`m use JS:
var path = window.location.pathname.substring(1);
var noindex = ['user','search'];
noindex.forEach(el => {
if (path.indexOf(el) > -1) {
setNoindex();
return;
}
});
function setNoindex() {
var meta = document.createElement('meta');
meta.name = 'robots';
meta.setAttribute('content', 'noindex');
document.getElementsByTagName('head')[0].appendChild(meta);
}
Comments
I`m use JS:
var path = window.location.pathname.substring(1);
var noindex = ['user','search'];
noindex.forEach(el => {
if (path.indexOf(el) > -1) {
setNoindex();
return;
}
});
function setNoindex() {
var meta = document.createElement('meta');
meta.name = 'robots';
meta.setAttribute('content', 'noindex');
document.getElementsByTagName('head')[0].appendChild(meta);
}
Thanks for the suggestion, but I don't know where to put that.
This should be placed in your default theme script.js file.
https://docs.backdropcms.org/creating-themes
Since I'm using a sub-theme of Snazzy, it would go in the sub-theme as a new file?
Neither Snazzy or snazzytoys currently have this file - snazzytoys is set as the default theme in Backdrop.
Open your theme folder,
the mytheme.info file lists the scripts (and CSS) connected to the theme:
scripts[] = myscript.js
(see docs https://docs.backdropcms.org/creating-themes)
If there are no scripts, add this line,
create myscript.js, paste the code into it:
$(document).ready(function() {
console.log('This message will be displayed in the console if the script is connected correctly');
// Any code will be here
});
Clear cache.
For an example, see the structure
/core/themes/basis/basis.info
@Enthusiast - Thank you for your help. I have read through the doc you linked to and now have a slightly better understanding of what is happening.
For a long time I used ready-made themes for my websites, or used theme generation software, I thought that making themes myself was too difficult for me.
When I decided and figured out this issue, it turned out to be not so difficult. Now I can copy the design of any website, I can satisfy any design requirements of clients. I freed myself from dependence on ready-made themes.
CSS, JS (Jquery), little PHP, all this turned out to be very entertaining, I work with pleasure. Therefore, I advise everyone: don’t stand still, move forward, don’t be afraid to learn something new. You can do what others can do.
Open your theme folder,
the mytheme.info file lists the scripts (and CSS) connected to the theme:
scripts[] = myscript.js
(see docs https://docs.backdropcms.org/creating-themes)
If there are no scripts, add this line,
create myscript.js, paste the code into it:
$(document).ready(function() {
console.log('This message will be displayed in the console if the script is connected correctly');
// Any code will be here
});
Clear cache.
For an example, see the structure
/core/themes/basis/basis.info