Dynamically altering post title

I’m wanting (for complicated reasons) to dynamically change an individual Post/Page title (for front-end browser display purposes only, not in DB).

However, for reasons, I need to do this on the fly within the actual post’s content using PHP-Exec plugin (allowing me to do PHP in the post) and possibly, WP hooks/actions etc.

I have 1 WP page, that using htaccess and Exec-PHP will act as a template for many different article pages, and thus when that page is called (from one of the many different URLs that will call it), the page will access the DB, and retrieve an article title, and article body based on the calling URL.

The resulting outputted page will have that article body in it - achievable as Exec-PHP is being using in the Post body to do all this.

However I also need to also change the Post title (that appears in the browser top, and in the templates <h1> tags etc) to reflect the article title from the DB. This is the problem, I can’t work out how to change the page title using exec-php in the page content.

Is there anyway I could alter these titles on the run, using WP hooks/actions or whatever?

Is this even possible? If so, how? :slight_smile:

Hoping this makes sense.

Thx

This is what I would recommend, too. In your custom field, add browser_title or just title under name. Add a conditional in your title tag like so:

<title>
<?php if (is_single()) {  
  $key="title"; echo get_post_meta($post->ID, $key, true);
 } else { wp_title(); } ?>
</title>

More about custom fields: http://codex.wordpress.org/Custom_Fields

Couldn’t you simply use a custom field and add whatever you want changed in the title in that custom field? That way you don’t have to mess with PHP-Exec and trying to execute it from within the post, you’ll simply type in what you want.

See if this article I wrote a couple years ago helps out. I think it will.

http://www.1955design.com/2007/09/14/optimize-wordpress-page-headings/

I’m not sure I understand, but that’s probably my limitation and not your description causing this problem!

Can you address this issue in the <header> of the page?

Thanks for the reply, though I am not sure if that helps in this situation. I’ve got a fairly unique situation where I want to alter this wordpress post’s (which acts like a template) title dynamically from within the confines of the wordpress post content (where I have access to php thanks to the PHP-Exec plugin). This wordpress post acts as template for some articles in another, NON-WP, DB and the page is called by using a custom mod-rewrite rule I have created. eg /articles/article-about-something (where /articles/* is a non WP permalink that points to this specific post).

So from within the wordpress post body, using PHP-Exec I need to somehow alter the title, so that when it gets incorporated within the WP theme (h1 area) and browser title bar, it display’s this articles title (from DB), rather than the WP post’s actual title - otherwise all 300 articles pulled from the DB will have the same non-descriptive WP post title.

Also I only need to bother about this from with this WP post itself, and not links pointing to it etc (i’ve already done that).

Hoping this makes some sense :slight_smile: