Update: After upgrading Perishable Press in 2007, many of the hacks listed on this page are no longer applicable. Please refer to our new WordPress Core Edits for current information. Otherwise, this article remains online for reference purposes only.
The folks developing WordPress are continually rolling out “upgrades”. While it is generally a good idea to stay current, it can also be a bit of a pain if you have made any changes to the WordPress core files. Our recommendation? Keep a log such as this one that either includes all edits or links to posts describing them. That way, when it is time to upgrade to WP 3.0.1, WP 3.0.2, … WP 9.0.1, WP 9.0.2 … (you get the idea), it will simply be a matter of referring to your handy WP core file change log and then going thru the list, copying & pasting your way back to complete functionality. Just remember to add any subsequent changes to the list, though, or you may find yourself scratching your head after the next upgrade. Another good idea involves carefully comparing any code you are replacing, checking to make sure the wizards at WordPress haven’t changed any aspects of the original code (of which you are replacing).
So, without further ado, here are the WordPress core file edits currently operating here at Perishable Press:
Customize the_excerpt function
File: wp-includes/functions-formatting.php (~ lines #763 & 767): set to desired values:
$excerpt_length = 50;
...
array_pop($words);
array_push($words, '[...] ( click post title to read more )');
$text = implode(' ', $words);
Customize the wpautop function
File: wp-includes/functions-formatting.php (~ line #72, #83):
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n\t\t\t\t\t\t", $pee); // make paragraphs, including one at the end
$pee = str_replace("<p><!--", "<!--", $pee);
$pee = str_replace("--></p>", "-->", $pee);
return $pee;
Customize the more quicktag
File: wp-includes/template-functions-post.php (~ lines #54, 62, 92):
function the_content($more_link_text = 'Continued >>', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
}
...
function get_the_content($more_link_text = 'Continued >>', $stripteaser = 0, $more_file = '') {
global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages;
global $preview;
global $pagenow;
$output = '';
...
...
else
//$output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";
$output .= ' <a href="'. get_permalink() . "\">$more_link_text</a>";
}
Customize Default Password Text
File: wp-includes/comment-functions.php (~ line #296):
Password Required
WordPress RDF Source Makeover
File: wp-includes/comment-functions.php (~ line #513):
function trackback_rdf($timezone = 0) {
global $id;
if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) {
echo '<rdf:RDF ';
echo "\n";
echo ' xmlns:dc="http://purl.org/dc/elements/1.1/" ';
echo "\n";
echo ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ';
echo "\n";
echo ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">';
echo "\n";
echo '<rdf:Description ';
echo "\n";
echo ' dc:creator="';
the_author();
echo '" '."\n";
echo ' dc:date="';
the_date_xml();
echo ' @ ';
the_time('g:i a');
echo '" '."\n";
echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'" '."\n";
echo ' rdf:about="';
the_permalink();
echo '" '."\n";
echo ' dc:identifier="';
the_permalink();
echo '" '."\n";
echo ' trackback:ping="'.trackback_url(0);
echo '" '."\n";
echo ' dc:description="';
the_excerpt_rss();
echo '" />'."\n";
echo '</rdf:RDF>';
}
}
And then replace the_excerpt_rss(); with:
the_content_rss('', TRUE, '', 7, 2);
Title Attributes for WordPress Post Navigation
File: wp-includes/template-functions-links.php (~ lines #348, 369, 459, 494, 503):
$string = '<a href="'.get_permalink($post->ID).'" title="Go to previous post">'.$previous;
...
$string = '<a href="'.get_permalink($post->ID).'" title="Go to next post">'.$next;
...
...
function next_posts_link($label='Next Page »', $max_page=0) {
...
echo '" title="Go backward in time">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
...
function previous_posts_link($label='« Previous Page') {
...
echo '" title="Go forward in time">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
...
function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') {
Vars Tweak for htaccess Edits
File: wp-includes/vars.php (~ #35):
// Server detection
//the next line is used to allow WP to write htaccess rules during permalink creation (comment out the $is_apache line first)
//$is_apache = 1;
$is_apache = ( strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') || strstr($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') ) ? 1 : 0;
Customize Password-Protected Posts
File: template-functions-post.php (~ line #3):
function get_the_password_form() {
$output = '<form action="' . get_settings('siteurl') . '/wp-pass.php" method="post">
<p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
<p><small><label class="h">' . __("Password: ") . ' </label><input class="postpassword" name="post_password" type="password" size="11" /> <input class="passwordsubmit" type="submit" name="Submit" value="' . __("Submit »") . '" /></small></p>
</form>
<div class="clear vspace"> </div>
';
return $output;
}
Reversing WordPress Post Navigation Order
File: template-functions-links.php (~ lines #503, 518):
Note: It looks like this change has been implemented (as of WP 2.0.5)..
function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') {
...
if ( $max_num_pages > 1 ) {
previous_posts_link($prelabel);
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
next_posts_link($nxtlabel, $max_page);
}
Customize Quicktag Buttons
File: wp-includes/js/quicktags.js (~ line #37):
Required edit: delete the empty spaces out of the "pre code" button.
// CUSTOM QUICKTAGS BEGIN HERE
edButtons[edButtons.length] = new edButton('ed_authent'
,'authenticate'
,'<!--authenticate-->'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_quotes'
,'quotes'
,'“'
,'”'
,''
);
edButtons[edButtons.length] = new edButton('ed_dash'
,'dash'
,'—'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_rsquo'
,'rsquo'
,'’'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_lsquo'
,'lsquo'
,'‘'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_acronym'
,'acronym'
,'<acronym title="">'
,'</acronym>'
,''
);
edButtons[edButtons.length] = new edButton('ed_clearspace'
,'clearspace'
,'<div class="clear vspace"> </div>'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_follow'
,'follow link'
,'<a href="" title="">'
,'</a>'
,''
);
edButtons[edButtons.length] = new edButton('ed_nofollow'
,'nofollow link'
,'<a href="http://" title="" rel="nofollow">'
,'</a>'
,''
);
edButtons[edButtons.length] = new edButton('ed_press-link'
,'press link'
,'<a href="http://perishablepress.com/" title="Perishable Press">'
,'</a>'
,''
);
edButtons[edButtons.length] = new edButton('ed_reflist'
,'ref list'
,'<h3 class="references"></h3>\n\t<ul class="refs">\n\t<li><sup>1</sup> <a href="http://" title=""></a></li>\n\t<li><sup>2</sup> <a href="http://" title=""></a></li>\n'
,'</ul>'
,''
);
edButtons[edButtons.length] = new edButton('ed_content-link'
,'content-link'
,'<a href="http://perishablepress.com/press/wp-content/online/" title="Perishable Press">'
,'</a>'
,''
);
edButtons[edButtons.length] = new edButton('ed_press-image'
,'press image'
,'<img src="http://perishablepress.com/press/wp-content/images/" title="" alt="" />'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_pre-code'
,'pre code'
,'< pre>< code>'
,'< /code>< /pre>'
,''
);
edButtons[edButtons.length] = new edButton('ed_sup'
,'sup'
,'<sup>'
,'</sup>'
,''
);
edButtons[edButtons.length] = new edButton('ed_quot'
,'quot'
,'"'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_<'
,'<'
,'<'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_>'
,'>'
,'>'
,''
,''
);
// CUSTOM QUICKTAGS END HERE
Remove the Admin Post-Preview Panel
File: wp-admin/post.php (line #83) & wp-admin/edit-form-advanced.php (line 17):
First, open wp-admin/post.php and delete these lines:
<div id='preview' class='wrap'>
<h2 id="preview-post"><?php _e('Post Preview (updated when post is saved)'); ?> <small class="quickjump"><a href="#write-post"><?php _e('edit ↑'); ?></a></small></h2>
<iframe src="<?php echo wp_specialchars(apply_filters('preview_post_link', add_query_arg('preview', 'true', get_permalink($post->ID)))); ?>" width="100%" height="600" ></iframe>
</div>
Then, open wp-admin/edit-form-advanced.php and delete these lines:
<?php if ( 0 != $post_ID ) : ?>
<small class="quickjump"><a href="#preview-post"><?php _e('preview ↓'); ?></a></small>
<?php endif; ?>
Enhance parse_url Functionality
File: wp-includes/functions.php (~ lines #1067): insert "@" before parse_url and praise the Lord!
Remove CSS Link to Print Stylesheet
File: press/wp-subscription-manager.php (~ line #100): delete the following line to eliminate unnecessary 404 errors when users subscribe/unsubscribe to comments (or when managing subscriptions):
<link rel="stylesheet" type="text/css" media="print" href="<?php echo get_settings('siteurl'); ?>/print.css" />
Customize Comment Feed Link
File: wp-includes/feed-functions.php (line #84): edit according to current default theme requirements:
echo "<a href='$url'>$link_text</a>";
--- changed to --->
echo "<a class=\"feed-icon\" href='$url' title=\"Subscribe to comments for this article\" rel=\"nofollow\">$link_text</a>";
Customize Commentator Links
File: wp-includes/comment-functions.php (~lines #358-368): swap the following:
/* original */
function get_comment_author_link() {
global $comment;
$url = get_comment_author_url();
$author = get_comment_author();
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "<a href='$url' rel='external nofollow'>$author</a>";
return apply_filters('get_comment_author_link', $return);
}
// core file edit listed at perishablepress.com
// http://perishablepress.com/wordpress-core-file-edits/
function get_comment_author_link() {
global $comment;
$url = get_comment_author_url();
$author = get_comment_author();
if($comment->comment_type == 'pingback' || $comment->comment_type == 'trackback' ) {
if ( empty( $url ) || 'http://' == $url ) {
$return = $author;
} else {
$return = '<a href="'.$url.'" rel="external">'.$author.'</a>';
}
} else {
if ( empty( $url ) || 'http://' == $url ) {
$return = $author;
} elseif ( $author == 'blacklist' ) {
$return = '<a href="'.$url.'" rel="external nofollow">'.$author.'</a>';
} else {
$return = '<a href="'.$url.'" rel="external">'.$author.'</a>';
}
}
return apply_filters('get_comment_author_link', $return);
}
References
- Article #42: WordPress Notes Plus
- Article #49: RDF Source Code Makeover
- Article #90: Permalink Enlightenment
- Article #107: Title Attributes for WordPress Post Navigation
- Article #134: Customize Password-Protected Posts
- Article #147: Reversing WordPress Post Navigation Order
- Article #204: Customize WordPress Quicktags
- Article #244: WordPress on Crack
- Article #400: One-Minute Dofollow Upgrade
4 Responses
m0n – August 21, 2006
Add radio inputs for each item to simplify the upgrade customization process.
Perishable – August 21, 2006
Thanks for the idea!
1mil – February 3, 2007
What exactly does wp-includes/js/quicktags.js do, I couldnt get it to work like I thought it would. No buttons in the Editor.
1mil
Perishable – February 4, 2007
1mil,
As indicated in the introduction of this post, the various code examples offered in this article apply to Perishable Press. We refer to this article during each WordPress upgrade, as it helps facilitate expediency and accuracy throughout the core-editing process. Although the code functions properly at perishablepress.com, it may or may not work "as is" on other sites, and therefore exists online for reference purposes only.
For more help concerning quicktags, please consult this excellent article on the subject (404 link removed 2012/10/15).
Good luck!