Site logo

Archived topic

Dynamic Page Title

10 replies · Started by Juergen on September 13, 2016

Viewing posts 1–11 of 11

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!
Juergen

Hi 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,
Juergen

That looks good to me.. Have you tested if your option is returning on or not?

Hi 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!
Juergen

Hi 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,
Juergen

You 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 :)

Hi 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
Juergen

Hi,

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,
Juergen

Awesome!

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".

This archived topic is closed to new replies.