Php 更改wordpress wp_get_存档功能的URL
我正在使用Wordpress中的Php 更改wordpress wp_get_存档功能的URL,php,wordpress,Php,Wordpress,我正在使用Wordpress中的wp\u get\u archives功能 <?php $args = array( 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_c
wp\u get\u archives
功能
<?php $args = array(
'type' => 'monthly',
'limit' => '',
'format' => 'html',
'before' => '',
'after' => '',
'show_post_count' => false,
'echo' => 1,
'order' => 'DESC'
); ?>
<?php wp_get_archives( $args ); ?>
但是我希望能够更改URL,而不是将其转到我的Wordpress安装目录,如何将其更改为我自己的自定义URL
PS:我在
通用模板上找到了。从第937行开始的php
文件是这个函数的开始处。我看到,在函数wp\u get\u archives
中,链接是用函数构建的。在那里,我们找到了过滤器钩子get\u archives\u link
,它返回归档文件的每个HTML链接
因此,我们可以操纵每个字符串并替换它们:
add_filter( 'get_archives_link', function( $html )
{
if( is_admin() ) // Just in case, don't run on admin side
return $html;
// $html is '<li><a href='http://example.com/hello-world'>Hello world!</a></li>'
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );
return $html;
});
add_filter('get_archives_link',函数($html)
{
如果(is_admin())//以防万一,不要在管理端运行
返回$html;
//$html是“”
$html=str_replace('href='http://example.com“,”href=”http://example.org“,$html);
返回$html;
});
brasofilo的解决方案对我来说很有效,只是做了一些小的调整
之前:
$html = str_replace( 'href="http://example.com', 'href="http://example.org', $html );
之后:
$html = str_replace( 'http://example.com', 'http://example.com/the_events', $html );