最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Insert nofollow in a "Powered By" link, except in the homepage

programmeradmin6浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I want to insert the nofollow value in a "Powered by" link if the page is different than the homepage.

So I have written this:

function prefix_poweredby() {
    if ( is_front_page() ) {
        $html = '<a href="; target="_blank">link</a>';
        echo $html;
    } else {
        $html = '<a href="; rel="nofollow" target="_blank">link</a>';
        echo $html;
    }
}
add_action('wp_footer', 'prefix_poweredby');

It's working just fine, but I'm pretty sure that there are other more elegant ways to write this function and I would love if you could share with me.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 4 years ago.

Improve this question

I want to insert the nofollow value in a "Powered by" link if the page is different than the homepage.

So I have written this:

function prefix_poweredby() {
    if ( is_front_page() ) {
        $html = '<a href="https://example" target="_blank">link</a>';
        echo $html;
    } else {
        $html = '<a href="https://example" rel="nofollow" target="_blank">link</a>';
        echo $html;
    }
}
add_action('wp_footer', 'prefix_poweredby');

It's working just fine, but I'm pretty sure that there are other more elegant ways to write this function and I would love if you could share with me.

Share Improve this question asked Sep 22, 2020 at 18:29 drabellodrabello 4032 gold badges5 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I don't know if it's any more elegant, but if you don't like duplicating the HTML code, you could do this:

function prefix_poweredby() {
    $html = '<a href="https://example"';
    if ( ! is_front_page() ) {
       $html .= ' rel="nofollow"';
    }
    $html .= ' target="_blank">link</a>';
    echo $html;
}
add_action('wp_footer', 'prefix_poweredby');
发布评论

评论列表(0)

  1. 暂无评论