[wp-trac] [WordPress Trac] #19135: wp_get_archives() needs a hook/filter
WordPress Trac
wp-trac at lists.automattic.com
Sat Nov 5 20:20:01 UTC 2011
#19135: wp_get_archives() needs a hook/filter
--------------------------+------------------------------
Reporter: LeviMorrison | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: 2nd-opinion |
--------------------------+------------------------------
Changes (by scribu):
* keywords: needs-patch => 2nd-opinion
* milestone: Future Release => Awaiting Review
Old description:
> I would expect that it would have one. It was proposed at one point:
> http://core.trac.wordpress.org/ticket/2329
>
> Consider the case where I want to add `rel="nofollow"` to links in my
> archive:
>
> {{{
> function nofollow($string) {
> $dom = DOMDocument::loadXML($string);
> $list = $dom->getElementsByTagName('a');
> foreach($list as $a) {
> if (!$a->hasAttribute('rel')) {
> $a->setAttribute('rel', 'nofollow');
> }
> }
> return $dom->saveHTML();
> }
> ob_start();
> wp_get_archives('type=monthly&limit=12');
> echo nofollow(ob_get_clean());
> }}}
>
> That seems really ugly, especially since I already use the nofollow
> function in other places using `apply_filter`;
>
> A more elegant way:
> {{{
> function wrap($string, $tag) {
> return "<$tag>$string</$tag>";
> }
> function nofollow($string) {
> $dom = DOMDocument::loadXML($string);
> $list = $dom->getElementsByTagName('a');
> foreach($list as $a) {
> if (!$a->hasAttribute('rel')) {
> $a->setAttribute('rel', 'nofollow');
> }
> }
> return $dom->saveHTML();
> }
> add_filter('wp_get_archives', 'wrap', 'ul');
> add_filter('wp_get_archives', 'nofollow');
> wp_get_archives('type=monthly&limit=12');
> }}}
New description:
I would expect that it would have one. It was proposed at one point: #2329
Consider the case where I want to add `rel="nofollow"` to links in my
archive:
{{{
function nofollow($string) {
$dom = DOMDocument::loadXML($string);
$list = $dom->getElementsByTagName('a');
foreach($list as $a) {
if (!$a->hasAttribute('rel')) {
$a->setAttribute('rel', 'nofollow');
}
}
return $dom->saveHTML();
}
ob_start();
wp_get_archives('type=monthly&limit=12');
echo nofollow(ob_get_clean());
}}}
That seems really ugly, especially since I already use the nofollow
function in other places using `apply_filter`;
A more elegant way:
{{{
function wrap($string, $tag) {
return "<$tag>$string</$tag>";
}
function nofollow($string) {
$dom = DOMDocument::loadXML($string);
$list = $dom->getElementsByTagName('a');
foreach($list as $a) {
if (!$a->hasAttribute('rel')) {
$a->setAttribute('rel', 'nofollow');
}
}
return $dom->saveHTML();
}
add_filter('wp_get_archives', 'wrap', 'ul');
add_filter('wp_get_archives', 'nofollow');
wp_get_archives('type=monthly&limit=12');
}}}
--
--
Ticket URL: <http://core.trac.wordpress.org/ticket/19135#comment:11>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list