SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

    Hoping this makes sense.

    Thx

  2. #2
    SitePoint Guru dwzemens's Avatar
    Join Date
    Mar 2005
    Location
    United States
    Posts
    768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See if this article I wrote a couple years ago helps out. I think it will.

    http://www.1955design.com/2007/09/14...page-headings/
    Web Design, Marketing, Etc .............
    ....

  3. #3
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    SitePoint Guru dwzemens's Avatar
    Join Date
    Mar 2005
    Location
    United States
    Posts
    768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    Web Design, Marketing, Etc .............
    ....

  5. #5
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Member mpaulino's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by indianabenny View Post
    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.
    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:

    PHP Code:
    <title>
    <?php if (is_single()) {  
      
    $key="title"; echo get_post_meta($post->ID$keytrue);
     } else { 
    wp_title(); } ?>
    </title>
    More about custom fields: http://codex.wordpress.org/Custom_Fields


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •