Title: Use custom code for custom page title
Last modified: February 1, 2017

---

# Use custom code for custom page title

 *  Resolved [drreen](https://wordpress.org/support/users/drreen/)
 * (@drreen)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/)
 * For a specific page I would like to use an SEO title which includes a php code
   snippet so that the current month is displayed.
 * Is there a way to achieve that through a functions.php entry?

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Sybre Waaijer](https://wordpress.org/support/users/cybr/)
 * (@cybr)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/#post-8723823)
 * Hi [@drreen](https://wordpress.org/support/users/drreen/),
 * That’s indeed possible 🙂
 * It will only work if your theme is outputting the title correctly, or when the
   title has been fixed through the Title Fix extension.
 * This is what the code will look like, you can ignore the 2nd and 3rd parameters(`
   $args` and `$escape`).
 *     ```
       add_filter( 'the_seo_framework_pro_add_title', 'my_pro_title_alterations', 10, 3 );
       /**
        * Alter title after it has been processed.
        *
        * @param string $title The current title.
        * @param array $args The title args
        * @param bool $escape Whether the title is being escaped in this call.
        * @return string The full title.
        */
       function my_pro_title_alterations( $title = '', $args = array(), $escape = true ) {
   
       	//* If it's a post:
       	if ( is_single() ) {
       		// You can change 'F' with any of these date codes:
       		// @link http://php.net/manual/en/function.date.php
       		$title = get_the_date( 'F' ) . ' - ' . $title;
       	}
   
       	//* If it's a page:
       	if ( is_page() ) {
       		// Code here
       	}
   
       	//* If it's an archive:
       	if ( is_archive() ) {
       		// Code here
       	}
   
       	//* If the current Post ID is 3
       	// Don't use get_the_ID as it can cross with archives.
       	if ( 3 === get_queried_object_ID() ) {
       		// Per your request, with i18n support:
       		$title = date_i18n( 'F', true, false ) . ' - ' . $title;
       	}
   
       	return $title;
       }
       ```
   
 * If you have any questions, feel free to ask! Cheers 🙂
 * Edit: After re-reading your request, I’ve updated the code snippet.
    -  This reply was modified 9 years, 3 months ago by [Sybre Waaijer](https://wordpress.org/support/users/cybr/).
    -  This reply was modified 9 years, 3 months ago by [Sybre Waaijer](https://wordpress.org/support/users/cybr/).
      Reason: Typo in code
 *  Thread Starter [drreen](https://wordpress.org/support/users/drreen/)
 * (@drreen)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/#post-8723884)
 * Thx!
 * Actually I intended to use not the current month as SEO title for whole website.
   The date is part of the SEO title for the whole website.
 * The desired SEO title for whole website:
    `Title is here - <?php echo date_i18n('
   F Y') ?>`
 * //edit: sorry for the confusion – it’s actually supposed to be for seo title 
   for whole website
    Yet the code is super useful and great for customization in
   the future! 🙂
    -  This reply was modified 9 years, 3 months ago by [drreen](https://wordpress.org/support/users/drreen/).
    -  This reply was modified 9 years, 3 months ago by [drreen](https://wordpress.org/support/users/drreen/).
 *  Plugin Author [Sybre Waaijer](https://wordpress.org/support/users/cybr/)
 * (@cybr)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/#post-8723916)
 * Hi [@drreen](https://wordpress.org/support/users/drreen/),
 * Could you list a few example titles of what you wish it to become?
 * For example, any of these:
 *     ```
       Post Title - Current Date - My website
       Post Title - Post Date - My website
       Post Title - Post Date
       Post Title - Current Date
       Current Date - Post Title - My Website
   
       // Only if archive:
       Archive Title - Month updated - My Website
   
       etc.
       ```
   
 * Thanks!
 *  Thread Starter [drreen](https://wordpress.org/support/users/drreen/)
 * (@drreen)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/#post-8723962)
 * It’s supposed to be a completely custom title!
 * Custom Title beginning – Current Month and Year
 * Eg. Website title – January 2017
 *  Plugin Author [Sybre Waaijer](https://wordpress.org/support/users/cybr/)
 * (@cybr)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/#post-8724277)
 * Hi @ddreen,
 * Then I believe you require this (note, it’s now “pre”):
 *     ```
       add_filter( 'the_seo_framework_pre_add_title', 'my_pre_title_alterations', 10, 3 );
       /**
        * Alter title before it is processed.
        *
        * @param string $title The current title.
        * @param array $args The title args
        * @param bool $escape Whether the title is being escaped in this call.
        * @return string The title part.
        */
       function my_pre_title_alterations( $title = '', $args = array(), $escape = true ) {
       	return date_i18n( 'F Y', time(), false );
       }
       ```
   
 * Please be aware that if you have multiple pages on your website, the code above
   will effectively eventually mark your website as spam.
 * Dynamic titles (based on time alone) are also highly discouraged.
    I recommend
   only altering a single page with the filter above.
 * Nevertheless, I hope this helps 🙂
    -  This reply was modified 9 years, 3 months ago by [Sybre Waaijer](https://wordpress.org/support/users/cybr/).
 *  Thread Starter [drreen](https://wordpress.org/support/users/drreen/)
 * (@drreen)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/#post-8728033)
 * Thanks for the help, I really appreciate it! 🙂
    I will consider your advice 
   and make a decision!
 *  Plugin Author [Sybre Waaijer](https://wordpress.org/support/users/cybr/)
 * (@cybr)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/#post-8729642)
 * Anytime! If you have any more questions, feel free to ask 🙂

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Use custom code for custom page title’ is closed to new replies.

 * ![](https://ps.w.org/autodescription/assets/icon.svg?rev=3000376)
 * [The SEO Framework – Fast, Automated, Effortless.](https://wordpress.org/plugins/autodescription/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autodescription/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autodescription/)
 * [Active Topics](https://wordpress.org/support/plugin/autodescription/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autodescription/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autodescription/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Sybre Waaijer](https://wordpress.org/support/users/cybr/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/use-custom-code-for-custom-page-title/#post-8729642)
 * Status: resolved