How to override wp_list_pages and wp_list_bookmarks without modify core code ?
-
Hi all !
I am finding a way to override some core functions of WordPress (wp_list_pages and wp_list_bookmarks) within my function.php theme file because I am so tired to always modify core code when I update WordPress.
In the way to make easier my css styling, I proceed of this changes in post-template.php and bookmark-template.php core file.
In one hand, I added in the $default array of the post-template.php wp_list_pages function the following parameters:
'before' => '', 'after' => ''
in the way to modify the Walker_Page start_el method at line 1062 from:
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';
to:
$output .= $indent . '<li class="' . $css_class . '">' . $before . '<a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>' . $after;
(as we can see these parameters in the wp_list_bookmarks function)
In the other hand, I added in the $default array of the bookmark-template.php _walk_bookmarks and wp_list_bookmarks functions the following parameter:
'relativepath' => 0
in the way to modify the part of code at line 102 in _walk_bookmarks function from:
if ( $bookmark->link_image != null && $show_images ) { if ( strpos($bookmark->link_image, 'http') === 0 ) $output .= "<img src=\"$bookmark->link_image\" $alt $title />"; else // If it's a relative path $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />"; if ( $show_name ) $output .= " $name"; } else { $output .= $name; }
to:
if ( $bookmark->link_image != null && $show_images ) { if ( $relativepath == 0 ) { if ( strpos($bookmark->link_image, 'http') === 0 ) $output .= "<img src=\"$bookmark->link_image\" $alt $title />"; else // If it's a relative path $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />"; } else { $output .= "<img src=\"" . wp_make_link_relative($bookmark->link_image) . "\" $alt $title />"; } if ( $show_name ) $output .= " $name"; } else { $output .= $name; }
(I need to have relative path for the src attribute of my img tag and I don’t find on other way even with hooks and filters)
I know it’s dangerous to modify core code but I don’t find on internet the way to obtain what I needed without hacking WordPress core files.
Is anybody have an idea to get around my hacking code ?
Thanks
- The topic ‘How to override wp_list_pages and wp_list_bookmarks without modify core code ?’ is closed to new replies.