如何在链接编辑器现有的“链接关系(XFN)选项”列表中添加“noollow”选项?

时间:2010-12-10 作者:Scott B

将“nofollow”选项添加到链接编辑器现有的“链接关系(XFN)选项列表”有多困难?

或者,或者更好的是,另外,在“批量操作”列表中添加一个名为“使链接不跟随”的项目,该项目将使所有选定的链接rel=“nofollow”。

我想将此功能添加到我的主题功能中。php

4 个回复
最合适的回答,由SO网友:t31os 整理而成

或者,您可以通过将队列重新指向xfn来撤消禁用关系框的代码。js脚本。。

首先创建该脚本的修改版本,如下所示。。

jQuery(document).ready( function($) {
    //$(\'#link_rel\').attr(\'readonly\', \'readonly\');
    $(\'#linkxfndiv input\').bind(\'click keyup\', function() {
        var isMe = $(\'#me\').is(\':checked\'), inputs = \'\';
        $(\'input.valinp\').each( function() {
            if (isMe) {
                $(this).attr(\'disabled\', \'disabled\').parent().addClass(\'disabled\');
            } else {
                $(this).removeAttr(\'disabled\').parent().removeClass(\'disabled\');
                if ( $(this).is(\':checked\') && $(this).val() != \'\')
                    inputs += $(this).val() + \' \';
            }
        });
        $(\'#link_rel\').val( (isMe) ? \'me\' : inputs.substr(0,inputs.length - 1) );
    });
});
另存为xfn.js 并放入插件文件夹或当前主题文件夹。

NOTE: 这是WordPress排队的原始(现有)脚本的直接副本,我留下了将rel输入设置为只读的原始代码,以便您可以查看更改的内容(一行)。

然后将其添加到插件代码或主题函数中。,并取消对代码示例中相应行的注释。。

function switch_xfn_src( $src, $handle ) {
    if( \'xfn\' == $handle )
        //$src = plugins_url( \'/xfn.js\', __FILE__ ); // For use inside plugin
        //$src = get_bloginfo( \'stylesheet_directory\' ) . \'/xfn.js\'; // For use inside theme
    return $src;
}
add_filter( \'script_loader_src\', \'switch_xfn_src\', 10, 2 );
工作完成了……:)

SO网友:Denis de Bernardy

我不确定是否存在过滤器或操作。如果是这样的话,就相当容易了。如果没有,请使用我的外部链接插件:

http://wordpress.org/extend/plugins/sem-external-links/

SO网友:goldenapples

这里有一个函数,它删除了现有的link\\u xfn元框,并添加了另一个相同的元框,其中带有“nofollow”复选框:

add_action( \'admin_menu\', \'nofollow_enabled_xfn_box\' );

function nofollow_enabled_xfn_box() {
    global $pagenow;
    if ( $pagenow != \'link.php\' ) return;

    remove_meta_box( \'linkxfndiv\', \'link\', \'normal\' );
    add_meta_box(\'linkxfndiv\', __(\'Link Relationship (XFN)\'), \'se5160_link_xfn_meta_box\', \'link\', \'normal\' );
}

/**
 * Modified xfn form fields box, with "nofollow" link.
 *
 * @based on function link_xfn_meta_box() (from /wp-admin/includes/meta-boxes.php)
 *
 * @param object $link
 */
function se5160_link_xfn_meta_box($link) {
?>
<table class="editform" style="width: 100%;" cellspacing="2" cellpadding="5">
    <tr>
        <th style="width: 20%;" scope="row"><label for="link_rel"><?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'rel:\') ?></label></th>
        <td style="width: 80%;"><input type="text" name="link_rel" id="link_rel" size="50" value="<?php echo ( isset( $link->link_rel ) ? esc_attr($link->link_rel) : \'\'); ?>" /></td>
    </tr>
    <tr>
        <td colspan="2">
            <table cellpadding="3" cellspacing="5" class="form-table">
                <tr>
                <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'nofollow\') ?> </th>
                <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'not a trusted link\') ?> </span></legend>
                    <label for="nofollow">
                    <input class="valinp" type="checkbox" name="nofollow" value="nofollow" id="nofollow" <?php xfn_check(\'seo\',\'nofollow\'); ?> />
                    <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'not a trusted link\') ?></label>
                    </fieldset></td>
                </tr>
                <tr>
                    <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'identity\') ?> </th>
                    <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'identity\') ?> </span></legend>
                        <label for="me">
                        <input type="checkbox" name="identity" value="me" id="me" <?php xfn_check(\'identity\', \'me\'); ?> />
                        <?php _e(\'another web address of mine\') ?></label>
                    </fieldset></td>
                </tr>
                <tr>
                    <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'friendship\') ?> </th>
                    <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'friendship\') ?> </span></legend>
                        <label for="contact">
                        <input class="valinp" type="radio" name="friendship" value="contact" id="contact" <?php xfn_check(\'friendship\', \'contact\'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'contact\') ?></label>
                        <label for="acquaintance">
                        <input class="valinp" type="radio" name="friendship" value="acquaintance" id="acquaintance" <?php xfn_check(\'friendship\', \'acquaintance\'); ?> />  <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'acquaintance\') ?></label>
                        <label for="friend">
                        <input class="valinp" type="radio" name="friendship" value="friend" id="friend" <?php xfn_check(\'friendship\', \'friend\'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'friend\') ?></label>
                        <label for="friendship">
                        <input name="friendship" type="radio" class="valinp" value="" id="friendship" <?php xfn_check(\'friendship\'); ?> /> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'none\') ?></label>
                    </fieldset></td>
                </tr>
                <tr>
                    <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'physical\') ?> </th>
                    <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'physical\') ?> </span></legend>
                        <label for="met">
                        <input class="valinp" type="checkbox" name="physical" value="met" id="met" <?php xfn_check(\'physical\', \'met\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'met\') ?></label>
                    </fieldset></td>
                </tr>
                <tr>
                    <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'professional\') ?> </th>
                    <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'professional\') ?> </span></legend>
                        <label for="co-worker">
                        <input class="valinp" type="checkbox" name="professional" value="co-worker" id="co-worker" <?php xfn_check(\'professional\', \'co-worker\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'co-worker\') ?></label>
                        <label for="colleague">
                        <input class="valinp" type="checkbox" name="professional" value="colleague" id="colleague" <?php xfn_check(\'professional\', \'colleague\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'colleague\') ?></label>
                    </fieldset></td>
                </tr>
                <tr>
                    <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'geographical\') ?> </th>
                    <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'geographical\') ?> </span></legend>
                        <label for="co-resident">
                        <input class="valinp" type="radio" name="geographical" value="co-resident" id="co-resident" <?php xfn_check(\'geographical\', \'co-resident\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'co-resident\') ?></label>
                        <label for="neighbor">
                        <input class="valinp" type="radio" name="geographical" value="neighbor" id="neighbor" <?php xfn_check(\'geographical\', \'neighbor\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'neighbor\') ?></label>
                        <label for="geographical">
                        <input class="valinp" type="radio" name="geographical" value="" id="geographical" <?php xfn_check(\'geographical\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'none\') ?></label>
                    </fieldset></td>
                </tr>
                <tr>
                    <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'family\') ?> </th>
                    <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'family\') ?> </span></legend>
                        <label for="child">
                        <input class="valinp" type="radio" name="family" value="child" id="child" <?php xfn_check(\'family\', \'child\'); ?>  />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'child\') ?></label>
                        <label for="kin">
                        <input class="valinp" type="radio" name="family" value="kin" id="kin" <?php xfn_check(\'family\', \'kin\'); ?>  />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'kin\') ?></label>
                        <label for="parent">
                        <input class="valinp" type="radio" name="family" value="parent" id="parent" <?php xfn_check(\'family\', \'parent\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'parent\') ?></label>
                        <label for="sibling">
                        <input class="valinp" type="radio" name="family" value="sibling" id="sibling" <?php xfn_check(\'family\', \'sibling\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'sibling\') ?></label>
                        <label for="spouse">
                        <input class="valinp" type="radio" name="family" value="spouse" id="spouse" <?php xfn_check(\'family\', \'spouse\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'spouse\') ?></label>
                        <label for="family">
                        <input class="valinp" type="radio" name="family" value="" id="family" <?php xfn_check(\'family\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'none\') ?></label>
                    </fieldset></td>
                </tr>
                <tr>
                    <th scope="row"> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'romantic\') ?> </th>
                    <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'romantic\') ?> </span></legend>
                        <label for="muse">
                        <input class="valinp" type="checkbox" name="romantic" value="muse" id="muse" <?php xfn_check(\'romantic\', \'muse\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'muse\') ?></label>
                        <label for="crush">
                        <input class="valinp" type="checkbox" name="romantic" value="crush" id="crush" <?php xfn_check(\'romantic\', \'crush\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'crush\') ?></label>
                        <label for="date">
                        <input class="valinp" type="checkbox" name="romantic" value="date" id="date" <?php xfn_check(\'romantic\', \'date\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'date\') ?></label>
                        <label for="romantic">
                        <input class="valinp" type="checkbox" name="romantic" value="sweetheart" id="romantic" <?php xfn_check(\'romantic\', \'sweetheart\'); ?> />
                        <?php /* translators: xfn: http://gmpg.org/xfn/ */ _e(\'sweetheart\') ?></label>
                    </fieldset></td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<p><?php _e(\'If the link is to a person, you can specify your relationship with them using the above form. If you would like to learn more about the idea check out <a href="http://gmpg.org/xfn/">XFN</a>.\'); ?></p>
<?php
}
很多core的copypasta,但它比黑客好。当然,您可以任意更改xfn选项。

SO网友:hakre

它已经在里面了。您只需在浏览器中停用javascript并重新加载页面。您现在可以自由进入nofollow.

如果你问自己为什么我知道这一点:related ticket is #14599: Link Manager does not support nofollow in Link Relationship (XFN)

结束

相关推荐