[wp-hackers] is it possible to change the_title halfway into the processing of a page/post?

Mike Little wordpress at zed1.com
Wed Feb 22 20:47:17 UTC 2012


On Wed, Feb 22, 2012 at 18:08, Haluk Karamete <halukkaramete at gmail.com>wrote:

> Thanks Mike.
> With your solution though, when I switch themes, wouldn't all that
> custom programming ( querying the db to get the record data / title
> etc ) be not accessible?
>
>
Yes you are right; and that is the criteria I use for choosing whether code
should go in functions.php or a plugin: "If I want to change themes, will
it break?"

So in this case the answer is "yes", so you need to put that code in a
plugin:

The template_redirect hook,
And the db access and display functions.
Add a hook for wp_title
add a hook for the_title
add a hook for 'the_content', that calls your display functions.
That way, any theme that calls the_content on your page will be get your
display output.

It was quicker to knock up an example than to explain the details. See
http://pastebin.com/qCRWE9C1

Hope that helps.


Mike
-- 
Mike Little
http://zed1.com/


More information about the wp-hackers mailing list