Topic Closed
mabu
182 Posts
1.4K Downloads
3 Themes
7 Plugins

I am looking for a php-code which expands the target="blank">  to  

rel="noopener" rel="nofollow"  target="_blank" 

-  which i want to insert for example into the drop_down_menu.php.

Perhaps has anybody solved this before ?

What i found was in javascript at https://html.com/attributes/a-target/   :

function externalLinks() {   for(var c = document.getElementsByTagName("a"), a = 0;a < c.length;a++) {     var b = c[a];     b.getAttribute("href") && b.hostname !== location.hostname && (b.rel = "nofollow")   } } ; externalLinks();

which adds rel="nofollow"  - but i  look for a php - version

 

 

 

Edited: 4 months ago#11345

juergen
1.4K Posts
50.3K Downloads
16 Plugins
design, web development & visual effects

There is currently no way to add arbitrary attributes to menu items, but as a workaround we can add Extra Content Areas to menus (since Typesetter 5.1), so…

  1. Create an Extra Content Area via Admin Toolbar -> Content -> Extra Content. Use "Editable Text" and call it e.g. "Nofollow Menu Link"
  2. Edit the new Area using CK Editor Source view and add your link e.g.
    <a class="nav-link" href="[your link]" target="_blank" rel="nofollow noopener">[Your Link Label]</a>
    (the "nav-link" class is needed with Bootstrap 4 navs)
  3. Go to Page Manager and add a new item to the menu, choose "Extra Content" from the tabs at the top of the popup, select your "Nofollow Menu Link" Area.

This should do the trick.

Edited: 4 months ago#11347

mabu
182 Posts
1.4K Downloads
3 Themes
7 Plugins

Thats good but not quite what i was looking for : I wanted a replacement of the above functioning(!) javascript with php-DOM or similar, which i can include in a php-file.

The JS-Code adds automatic to all external links a rel="nofollow" and target="blank" (by an init.js).

( i can also add in ckeditor under advanced -> relationship ->  nofollow ... - but for every single link...)

Edited: 4 months ago#11348

juergen
1.4K Posts
50.3K Downloads
16 Plugins
design, web development & visual effects

To add a rel="nofollow noopener" attribute to all links that already have a target="_blank" attribute would be

PHP:

<?php
global $page;
$page->jQueryCode .= '$(\'a[target="_blank"]\').attr("rel", "nofollow noopener");';
?>

… or in existing JS:

$(function(){ $('a[target="_blank"]').attr("rel", "nofollow noopener"); });

But I'm uncertain if all crawlers will comply with a rule that is implemented subsequently via javascript. Googlebot most likely will.

Edited: 4 months ago#11349

mabu
182 Posts
1.4K Downloads
3 Themes
7 Plugins

I found a solution approach at https://stackoverflow.com/questions/5037592/how-to-add-rel-nofollow-to-links-with-preg-replace (at the bottom)

There $html = load (file.htm) - here template.php etc.
Edited: 4 months ago#11350

Topic Closed

 

News

Typesetter 5.1
8/12/2017

Typesetter 5.0.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

Over 8 Times Faster Than Wordpress
5/3/2016

We've known for a long time that Typesetter is fast. It's something we take pride ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Luzern (Schweiz): * Konzeption, Planung und Erstellung Ihres Internet-Auftritts * Betreuung und Aktualisierung/Pflege Ihrer Website * ...

Find out more about our Provider Spotlight

Log In

  Register