WordPress Notes Plus
Welcome to Perishable Press! This article covers many different aspects of WordPress functionality, including customizing quicktags, deleting the cache, numbering comments & posts, changing password text, and displaying archive menus. Note that this article was written for previous versions (i.e., less than 2.0) of WordPress. Discrepancies may exist between the code presented in this post and that of more recent versions of WordPress.
Nonetheless, this information is presented for references purposes with the hope that it will prove useful for those working with everyone’s favorite blogging platform, WordPress!
Customize WordPress Quicktags
The more Quicktag:
The <
!--more-->
Quicktag breaks a post into “teaser” and content sections. Type a few paragraphs, insert this tag, then compose the rest of your post. On your blog’s home page you’ll see only those first paragraphs with a “(more…)” hyperlink, which when followed displays the rest of the post’s content.1
Customize the more Quicktag:
To customize the “(more…)” hyperlink, open the file “wp-includes/template-functions-post.php” and locate the following lines (around lines #54 & #62, respectively):
function the_content($more_link_text = '(more...)', $str...
function get_the_content($more_link_text = '(more...)', $str...
For each line, carefully replace (more...)
with whatever text you wish. Possibilities include Continued >>
and [ Read on... ]
.
Modify the Target of the more Quicktag:
To modify the target of the “(more…)” hyperlink, replace the following statement (located within “wp-includes/template-functions-post.php” around line #92):
$output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";
..with:
$output .= ' <a href="'. get_permalink() . "\">$more_link_text</a>";
The nextpage Quicktag:
The <
!--nextpage-->
Quicktag is similar to the more tag, except it can be used any number of times in a post, and each insert will “break” and paginate the post at that location. Hyperlinks to the paginated sections of the post are then generated in combination with the wp_link_pages()
or link_pages()
template tag.2
Customize the_excerpt Function
Open the file “wp-includes/functions-formatting.php” and find the following line of code (located around line #732):
array_push($words, '[...]');
To customize the continuation notation for excerpts, simply replace [...]
with the text of your choice. Something like “[...continued »]
” or “[ click post title to read more ]
” works just swell.
To change the default number of words included in excerpts, edit the 55
in the following line of code (located around line #728) to reflect the desired number of excerpt words:
$excerpt_length = 55;
Fix the WordPress "Remember Me" Option
If the WordPress admin seems to “forget” you even after following all of the proper protocols, try changing the actual link that takes you to your WP admin-login page. Change the link from /wp-login.php
(the file) to /wp-admin/
(the directory).
Cache Notes
It is totally safe to delete everything in the /wp-content/cache/
folder!
Custom Number of Posts
Sometimes it is nice to customize the number of posts displayed for different loops. For example, if you have different themes, it is possible for one theme to show five posts while another theme only shows one post. To pull it off, simply place the following line of PHP
before the loop:
<
?php query_posts('showposts=n'); ?>
Where "n
" represents the number of posts that the loop will display 3. Nice ;) Update: This method needs some work — seemed okay at first, but then links to posts always go to the first blog page..
Tweaking Comment Numbers
Instruct WordPress to begin each post’s comment numbers with the number "1" (or any number), and then proceed numerically thenceforth by adding this line at the top of comments.php..
<
?php $commentcount=1; // number of first comment for each post ?>
..and then placing this line at the location where you would like the comment numbers to appear:
<
?php echo $commentcount++; ?>
Another method for accomplishing the same thing involves replacing this code (located in comments.php)..
<?php if ( $comments ) : ?>
<?php foreach ($comments as $comment) : ?>
..with this..
<?php if ( $comments ) : ?>
<?php foreach ($comments as $comment) : $comment_count++;?>
..and then placing this line at the location where you would like the comment numbers to appear:
<
?php echo $commentcount++; ?>
Customize Default Password Text
To change the default WordPress password text, open the file "wp-includes/comment-functions.php", and scroll to around line #309. Look for the password text and change it to whatever you prefer. Note: this default password text is different than the password text specified in the comments.php file.
Dropdown Archive Menus
To create dropdown archive menus (using get_archives
), simply emulate one of the following chunks of code and tweak to suit:
<select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Daily Archives</option>
<?php get_archives('daily','33','option','','','FALSE'); ?>
</select>
<select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Daily Archives</option>
<?php get_archives('postbypost','33','option','','','FALSE'); ?>
</select>
<select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Monthly Archives</option>
<?php get_archives('monthly','12','option','','','TRUE'); ?>
</select>
<select name="archivemenu" onChange="document.location.href=this.options[this.selectedIndex].value;">
<option value="">Daily Archives</option>
<?php get_archives('daily','7','option','','','FALSE'); ?>
<option value="">Monthly Archives</option>
<?php get_archives('monthly','7','option','','','TRUE'); ?>
<option value="">Yearly Archives</option>
<?php get_archives('weekly','7','option','','','TRUE'); ?>
</select>
Footnotes
- 1 WordPress Codex on the “more” Quicktag
- 2 WordPress Codex Quicktags Summary
- 3 WP Template Tags: query_post
4 responses to “WordPress Notes Plus”
I am attempting to modify the text for the more tag, but I can’t seem to get it to change. I have found the two functions you mention, and the list the text ‘more..’, but that is not what is displayed when I use the tag.
Here are the functions copied out of my theme:
And here is the text that is being displayed:
Read the rest of this entry »
Any help you could offer would be greatly appreciated.
Militantplatypus,
The method of changing the "More.." tag described in this article changes the default More tag text, which affects the blog universally. This is useful if you have many themes or do not feel like adding extra code to your pages.
On the other hand, WordPress also provides a localized method of changing the More tag text. Simply open your theme’s
index.php
file and locate the following PHP call:<
? php the_content(); ?
>Add your preferred More tag text within the parentheses as follows:
<
? php the_content('Custom More text...'); ?
>Custom More tag text indicated locally will override the specified default text.
I’m using More quick tags for my blog, and after updating to new WordPress 2.1 it stopped showing full feed RSS. RSS shows my content until the More tag as well. How can I change it back so my RSS shows full feeds?
Thank you.
inspirationbit,
We have yet to upgrade to WP 2.1, so it is difficult to imagine the possible cause of your dilemma. However, we will try to investigate this issue once we are running 2.1.