Skip to main content
deleted 19 characters in body
Source Link
typologist
  • 793
  • 4
  • 8

Since you want to add this attribute only to custom URLs (those matching /user/*) within your content, you might have to write custom code, as I'm not aware of any module which does this.

You could use hook_preprocess_field() and then execute a regular expression to match your pattern and add the rel="nofollow" attribute. However, this could be highly inefficient, as you have to do it every time you render a node, besides the fact that parsing HTML with regular expressions is not a bullet-proof solution.

There'sHere it's a module, however, that does something similarvery: Path Nofollow

Specify paths on which a metatag is added to prevent search engines from indexing the page.

So you could specify the path /user/* and it will add a metatag simple example that just adds rel="nofollow" to all links in the head of your htmlbody field <meta name="robots" content="noindex">. As I said, not exactly the same, but(you will have to adapt it might help or complementto use your goal.

EDIT: Here's a code exampleown regular expression).

/**
 * Implements template_preprocess_field().
 */
function MYTHEME_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'body') {
     $markup = $variables['items']['0']['#markup'];
     $variables['items']['0']['#markup'] = preg_replace('/href=/', 'rel="nofollow" href=', $markup);
  }
}

Notice thatAnother alternative would be using the code above is a Path Nofollow module, that does something verysimilar simple example that just adds rel="nofollow" to all links in the body field;:

Specify paths on which a metatag is added to prevent search engines from indexing the page.

So you could specify the path /user/* and it will have to applyadd a metatag in the head of your own regular expressionhtml <meta name="robots" content="noindex">. As I said, not exactly the same, but it might help or complement your goal.

Since you want to add this attribute only to custom URLs (those matching /user/*) within your content, you might have to write custom code, as I'm not aware of any module which does this.

You could use hook_preprocess_field() and then execute a regular expression to match your pattern and add the rel="nofollow" attribute. However, this could be highly inefficient, as you have to do it every time you render a node, besides the fact that parsing HTML with regular expressions is not a bullet-proof solution.

There's a module, however, that does something similar: Path Nofollow

Specify paths on which a metatag is added to prevent search engines from indexing the page.

So you could specify the path /user/* and it will add a metatag in the head of your html <meta name="robots" content="noindex">. As I said, not exactly the same, but it might help or complement your goal.

EDIT: Here's a code example.

/**
 * Implements template_preprocess_field().
 */
function MYTHEME_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'body') {
     $markup = $variables['items']['0']['#markup'];
     $variables['items']['0']['#markup'] = preg_replace('/href=/', 'rel="nofollow" href=', $markup);
  }
}

Notice that the code above is a very simple example that just adds rel="nofollow" to all links in the body field; you will have to apply your own regular expression.

Since you want to add this attribute only to custom URLs (those matching /user/*) within your content, you might have to write custom code, as I'm not aware of any module which does this.

You could use hook_preprocess_field() and then execute a regular expression to match your pattern and add the rel="nofollow" attribute. However, this could be highly inefficient, as you have to do it every time you render a node, besides the fact that parsing HTML with regular expressions is not a bullet-proof solution.

Here it's a very simple example that just adds rel="nofollow" to all links in the body field (you will have to adapt it to use your own regular expression).

/**
 * Implements template_preprocess_field().
 */
function MYTHEME_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'body') {
     $markup = $variables['items']['0']['#markup'];
     $variables['items']['0']['#markup'] = preg_replace('/href=/', 'rel="nofollow" href=', $markup);
  }
}

Another alternative would be using the Path Nofollow module, that does something similar:

Specify paths on which a metatag is added to prevent search engines from indexing the page.

So you could specify the path /user/* and it will add a metatag in the head of your html <meta name="robots" content="noindex">. As I said, not exactly the same, but it might help or complement your goal.

added 656 characters in body
Source Link
typologist
  • 793
  • 4
  • 8

Since you want to add this attribute only to custom URLs (those matching /user/*) within your content, you might have to write custom code, as I'm not aware of any module which does this.

You could use hook_preprocess_node()hook_preprocess_field() and then execute a regular expression to match your pattern and add the rel="nofollow" attribute. However, this could be highly inefficient, as you have to do it every time you render a node, besides the fact that parsing HTML with regular expressions is not a bullet-proof solution.

There's a module, however, that does something similar: Path Nofollow

Specify paths on which a metatag is added to prevent search engines from indexing the page.

So you could specify the path /user/* and it will add a metatag in the head of your html <meta name="robots" content="noindex">. As I said, not exactly the same, but it might help or complement your goal.

EDIT: Here's a code example.

/**
 * Implements template_preprocess_field().
 */
function MYTHEME_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'body') {
     $markup = $variables['items']['0']['#markup'];
     $variables['items']['0']['#markup'] = preg_replace('/href=/', 'rel="nofollow" href=', $markup);
  }
}

Notice that the code above is a very simple example that just adds rel="nofollow" to all links in the body field; you will have to apply your own regular expression.

Since you want to add this attribute only to custom URLs (those matching /user/*) within your content, you might have to write custom code, as I'm not aware of any module which does this.

You could use hook_preprocess_node() and then execute a regular expression to match your pattern and add the rel="nofollow" attribute. However, this could be highly inefficient, as you have to do it every time you render a node.

There's a module, however, that does something similar: Path Nofollow

Specify paths on which a metatag is added to prevent search engines from indexing the page.

So you could specify the path /user/* and it will add a metatag in the head of your html <meta name="robots" content="noindex">. As I said, not exactly the same, but it might help or complement your goal.

Since you want to add this attribute only to custom URLs (those matching /user/*) within your content, you might have to write custom code, as I'm not aware of any module which does this.

You could use hook_preprocess_field() and then execute a regular expression to match your pattern and add the rel="nofollow" attribute. However, this could be highly inefficient, as you have to do it every time you render a node, besides the fact that parsing HTML with regular expressions is not a bullet-proof solution.

There's a module, however, that does something similar: Path Nofollow

Specify paths on which a metatag is added to prevent search engines from indexing the page.

So you could specify the path /user/* and it will add a metatag in the head of your html <meta name="robots" content="noindex">. As I said, not exactly the same, but it might help or complement your goal.

EDIT: Here's a code example.

/**
 * Implements template_preprocess_field().
 */
function MYTHEME_preprocess_field(&$variables) {
  if ($variables['element']['#field_name'] == 'body') {
     $markup = $variables['items']['0']['#markup'];
     $variables['items']['0']['#markup'] = preg_replace('/href=/', 'rel="nofollow" href=', $markup);
  }
}

Notice that the code above is a very simple example that just adds rel="nofollow" to all links in the body field; you will have to apply your own regular expression.

Source Link
typologist
  • 793
  • 4
  • 8

Since you want to add this attribute only to custom URLs (those matching /user/*) within your content, you might have to write custom code, as I'm not aware of any module which does this.

You could use hook_preprocess_node() and then execute a regular expression to match your pattern and add the rel="nofollow" attribute. However, this could be highly inefficient, as you have to do it every time you render a node.

There's a module, however, that does something similar: Path Nofollow

Specify paths on which a metatag is added to prevent search engines from indexing the page.

So you could specify the path /user/* and it will add a metatag in the head of your html <meta name="robots" content="noindex">. As I said, not exactly the same, but it might help or complement your goal.