- This topic has 10 replies, 2 voices, and was last updated 7 years, 7 months ago by Tom.
-
AuthorPosts
-
September 13, 2016 at 12:58 pm #226165Juergen
Hi,
I would like to use for two pages (post=117 and post=85) a dynamic title which is sent through a parameter within the link. The title should be created in a way like that:
“<title>New Page created on “.$_GET[last_update].”</title>”
Is that possible at the Generatepress theme? At the head.php I can only find the wp_head function.
Can you please advise where and how to use that functionality.
Thanks in advance!
JuergenSeptember 13, 2016 at 11:36 pm #226259TomLead DeveloperLead DeveloperHi there,
Take a look at the answer on this page: http://wordpress.stackexchange.com/questions/176940/add-theme-support-title-tag-in-conflict-with-custom-titles-function
It should help get you started π
September 14, 2016 at 12:20 pm #226456JuergenHi Tom,
thanks for your quick answer.
I tried a lot solutions along that direction, I think the following is the best but with no success.
At the end of the theme function.php file I added the following code:
add_filter( 'wp_title', 'custom_titles', 10, 2 ); function custom_titles( $title, $sep ) { //Check if custom titles are enabled from your option framework if ( ot_get_option( 'enable_custom_titles' ) === 'on' ) { //Some silly example $title = "Some other title" . $title;; } return $title; }
What am I doing wrong?
Thanks a lot for more details on this feature.
Regards,
JuergenSeptember 14, 2016 at 11:06 pm #226521TomLead DeveloperLead DeveloperThat looks good to me.. Have you tested if your option is returning on or not?
September 16, 2016 at 12:05 pm #227055JuergenHi Tom,
I do not understand what to test?
I can say that I added the code above to the Theme functions and after that I tested several pages but there is always the standard titles showing only.
Is there a requirement to modify another system setting?
Thanks again for feedback!
JuergenSeptember 16, 2016 at 12:10 pm #227058JuergenHi Tom,
I would like to send you the link to my project so that you might look at it. Is there a private message opportunity to give you the details?
Thanks,
JuergenSeptember 16, 2016 at 7:03 pm #227095TomLead DeveloperLead DeveloperYou need to make sure this option is return “on” as you’re asking it to:
ot_get_option( 'enable_custom_titles' ) === 'on'
You can test it like this:
add_action( 'generate_after_header','test_my_option' ); function test_my_option() { if ( ! function_exists( 'ot_get_option' ) ) return; if ( ot_get_option( 'enable_custom_titles' ) === 'on' ) { echo 'Im working!'; } }
If it’s working, that text should appear below your header.
If it’s not working, you’ll need to tweak the conditional and use the documentation provided by the plugin that created the function (ot_get_option).
Hope this helps π
September 17, 2016 at 1:52 pm #227305JuergenHi Tom,
thanks for your efforts. That helped a lot to understand some of the system functionalities. Unfortunately the code is not working because this function is part of a plugin’s shortcode I do not use.
However I have several ideas. There are a few questions I am not sure what is correct so please give me support:
add_filter( 'wp_title', 'custom_titles', 10, 2 );
Is this the right code to call a function in this example ‘custom_titles’ that modifies the Meta Title Tags?Is the functions.php in the theme folder the right place to put this code?
Is there a order where to add this code? Can it be at the end of the functions.php?
Thanks for these silly questions. I tried many different ways and it is not working so I want to be sure.
So many Thanks
JuergenSeptember 17, 2016 at 11:26 pm #227373TomLead DeveloperLead DeveloperThat’s correct, but you’ll want to use a child theme or the instructions here: https://generatepress.com/knowledgebase/adding-php-functions/
There’s no specific order, it will filter into the meta title regardless π
September 20, 2016 at 12:12 pm #228101JuergenHi,
I got it working now. The solution was: pre_get_document_title
Is there an option within Generatepress to input a standard Meta Description?
Thanks,
JuergenSeptember 20, 2016 at 1:24 pm #228134TomLead DeveloperLead DeveloperAwesome!
There’s not – that’s plugin territory as you wouldn’t want to lose that data if you switched themes. Try a plugin like “Add Meta Tags” or “Yoast SEO”.
-
AuthorPosts
- You must be logged in to reply to this topic.