Categories
Computers Programming

Custom More Text for WordPress Posts

How to supply custom ‘MORE’ link text via XMLRPC method calls.

A note to the less programming savvy readers out there, this one is full of programming jargon and can likely be safely ignored. In fact, unless you’re writing a blog client, you’re likely to find this one pretty uninteresting.

For those who are interested, the rest is after the link with the custom text…

I’ll try to keep this basically simple and explain the parameters that make this solution not completely obvious.

First, this explanation applies more specifically to the Metaweblog newPost method, which has a different post data structure from the now available native WordPress methods. This method would likely only be utilized in legacy situations and only applies to using this particular method with a WordPress blog. Those are the circumstances I found myself in when I started this endeavor.

Next, the post data structure used with the MetaWeblog newPost method has only 2 fields which pertain to post content: the description field and the mt_text_more field. These both accept a string as a value. The description field is what will be displayed on the main page of a blog. The mt_text_more is the additional portion of a post that will be displayed after clicking on a post’s MORE link.

My blog client splits the text as appropriate, using a specific text notation, and fills these two fields accordingly. When used like this, the WordPress software will always generate a MORE link, with no way to alter the text in that link.

To understand how to modify that text from an XMLRPC client, it is first necessary to know that WordPress splits it’s post content based on a specific HTML style comment in the post content. The comment looks like so:

<!--more-->

From a Metaweblog point-of-view, all content prior to that marker is the description and everything following is the mt_text_more. By inserting this HTML comment in the post content, it is unnecessary for the blog client to split the post into separate text fields. Instead, all of the content can be assigned to the description field in the post data structure for the newPost method and the mt_text_more field can be left empty. When used as above, the standard MORE link will appear on the blog.

To modify the text in the MORE link, modify the comment above by adding the custom text following the more in the HTML comment. For instance:

<!--more This Text Will Appear in the MORE Link-->

As stated, all the text following the more will be used in the link. That’s how I modified the link for this post you are reading.

For completeness, there is also a getPost method which returns a large data structure with all of a post’s metadata. One of the fields in the structure is called wp_more_text. Because the Metaweblog method splits the text, this field was added to provide the custom MORE text when retrieving a post via XMLRPC. It is blank if no custom text has been assigned. Note that this field has NO affect when assigned as part of the newPost data structure.

I’ll also note that the modified HTML more comment also applies when using the native WordPress XMLRPC newPost method. In fact, the post data structure used in that case does not provide for splitting the post content up like the Metaweblog method’s data structure. Therefore, it is necessary to always use the comment within the post content to split the post when rendered on the web.

Leave a Reply

Your email address will not be published. Required fields are marked *