Community Forums › Forums › Archived Forums › General Discussion › genesis_title showing outside tag with Simple Hooks
Tagged: Simple Hooks, title
- This topic has 7 replies, 3 voices, and was last updated 9 years, 10 months ago by Carlo.
-
AuthorPosts
-
December 29, 2014 at 7:05 am #135530mswasMember
I'm trying to replace the post title using Simple hooks. In the Document Hooks> genesis_title Hook: it says "This hook executes between the main document <title></title> tags." but whatever I place in that field shows AFTER the </title> tag.
My current theme is Beautiful Pro, but this happened with Metro and also just Genesis.
January 9, 2015 at 10:08 pm #136826TomParticipantPlease post the code exactly as you are using it.
(don't forget to use the "code" tags on your forum post)
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]January 10, 2015 at 5:13 am #136834CarloMemberI don't know why it says the hook executes between the title tags, because that's not how it works.
However, you can replace the post title in your post editing screen under 'Custom Document Title'.
Or, if you want to use a hook, you can use the
wp_title
hook like this, in your theme functions:add_filter( 'wp_title', function() { return 'My Replaced Title'; }, 20 );
or if you want to keep the title but add content to it, this should work:
add_filter( 'wp_title', function( $old_title ) { return sprintf( 'My Old Title was %s', $old_title ); }, 20 );
January 10, 2015 at 5:16 am #136835mswasMemberThanks Tom, this occurs with PHP and plain text. This is what I currently have in the genesis_title Hook field. with "Execute PHP on this hook?" checked.
| <?php echo get_field('book_title') . ' by ' . get_field('book_author') ; ?> Book Review
See that it is showing just outside </title> here: http://cannonballread.com/2015/01/afterworlds-if-schrodinger-ever-wrote-a-book/
<title>Afterworlds; If Schrödinger ever wrote a book</title>| Afterworlds by Scott Westerfeld Book Review
January 10, 2015 at 5:23 am #136838mswasMemberCarlo, I was writing my reply when you posted... Thanks for your suggestion. But this will not work for me to require the author to change on the post editing screen. We have over 170 bloggers now and it is very hard to get them every single one of them to do something consistently. I want this automated based on other custom fields that they are required to enter.
You can see my confusion based on what it says in the SH dashboard. I could have sworn that there was a field to append/replace title in previous versions of SH but maybe I was mistaken.
(edit - will try your other code tho.)
January 11, 2015 at 10:25 am #137050CarloMemberI see what you want to do now. Try this code: (it's the same idea as what I posted before the but tailored to match the format you posted)
add_filter( 'wp_title', function( $old_title ) { return sprintf( '%s | %s by %s Book Review', $old_title, get_field( 'book_title' ), get_field( 'book_author' ) ); }, 20 );
January 12, 2015 at 3:50 am #137144mswasMemberThanks Carlo, that is a much simpler bit of code than what I had found!
March 9, 2015 at 2:12 am #143757CarloMemberI recently published a tutorial on this topic:
http://carlomanf.id.au/modify-title-tags/
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.