New Bookstore! Save 20% on books with discount code: LAUNCH
Web Dev + WordPress + Security

WordPress Core File Edits at Perishable Press

[ WordPress Core Hacks ] 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. One thing that helps to stay organized is to keep a log that either includes all edits or links to posts describing them. That way, when it is time to upgrade WordPress, it simply will be a matter of referring to your handy WP core-file changelog 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.

Editor’s note: This article was written over 10 years ago, back when “hacking the WordPress core” was the only way to accomplish certain functionality. These days, WordPress has evolved to the point where you should never need to hack anything in the WordPress core files. Please keep that in mind while reading the following information.
Update: After upgrading Perishable Press in 2007, the hacks listed on this page no longer are applicable. Please refer to our new WordPress Core Edits for current information. Otherwise, this article remains online for historical and reference purposes only.

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.

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(']]>', ']]&gt;', $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('--', '&#x2d;&#x2d;', 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 &raquo;', $max_page=0) {
...
echo '" title="Go backward in time">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
...
function previous_posts_link($label='&laquo; Previous Page') {
...
echo '" title="Go forward in time">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
...
function posts_nav_link($sep=' &#8212; ', $prelabel='&laquo; Previous Page', $nxtlabel='Next Page &raquo;') {

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 &raquo;") . '" /></small></p>
	</form>
	<div class="clear vspace">&nbsp;</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=' &#8212; ', $prelabel='&laquo; Previous Page', $nxtlabel='Next Page &raquo;') {
...
if ( $max_num_pages > 1 ) {
	previous_posts_link($prelabel);
	echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep);
	next_posts_link($nxtlabel, $max_page);
}

Customize Quicktag Buttons

File: wp-includes/js/quicktags.js (~ line #37):

Note: remove the spaces on the pre code tags.

// CUSTOM QUICKTAGS BEGIN HERE

edButtons[edButtons.length] = new edButton('ed_authent'
,'authenticate'
,'<!--authenticate-->'
,''
,''
);

edButtons[edButtons.length] = new edButton('ed_quotes'
,'quotes'
,'&ldquo;'
,'&rdquo;'
,''
);

edButtons[edButtons.length] = new edButton('ed_dash'
,'dash'
,'&#8212;'
,''
,''
);

edButtons[edButtons.length] = new edButton('ed_rsquo'
,'rsquo'
,'&rsquo;'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_lsquo'
,'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">&nbsp;</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="https://perishablepress.com/" title="Perishable Press">'
,'</a>'
,''
);
edButtons[edButtons.length] = new edButton('ed_reflist'
,'ref list'
,'<h2 class="references"></h2>\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="https://perishablepress.com/wp/wp-content/online/" title="Perishable Press">'
,'</a>'
,''
);
edButtons[edButtons.length] = new edButton('ed_press-image'
,'press image'
,'<img src="https://perishablepress.com/wp/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'
,'&quot;'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_<'
,'<'
,'&lt;'
,''
,''
);
edButtons[edButtons.length] = new edButton('ed_>'
,'>'
,'&gt;'
,''
,''
);

// 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 &uarr;'); ?></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 &darr;'); ?></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
// https://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

Jeff Starr
About the Author
Jeff Starr = Web Developer. Book Author. Secretly Important.
.htaccess made easy: Improve site performance and security.

4 responses to “WordPress Core File Edits at Perishable Press”

  1. Add radio inputs for each item to simplify the upgrade customization process.

  2. Jeff Starr

    Thanks for the idea!

  3. 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

  4. Jeff Starr
    Perishable 2007/02/04 9:29 am

    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!

Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
Blackhole Pro: Trap bad bots in a virtual black hole.
Thoughts
Take a screenshot with Firefox (no extension required). Open Developer Tools Settings and enable the “Take a screenshot” button. Then click the button :)
Take a screenshot with Chrome (no extension required). Open DevTools, type Cmd + Shift + P, then type screenshot.
After 10 years working on my 2010 iMac, my upgrade finally arrived. Shiny new iMac shipped from Ireland :)
Too much caffeine weirds me out. But I love the taste of coffee. So once in a while I enjoy a small cup of decaf. Hits the spot.
Chris Coyier is a truly awesome person. One of the finest people I've ever worked with. Just #gottasayit
Excel won't open CSV file because SYLK format? Open it with text editor and add an apostrophe ' at the beginning of the file, save changes, done.
Displaying too many social media buttons and links all over the place imho makes you look desperate and frankly kinda sad.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.