[Resolved] Dynamic Page Title

Home Forums Support [Resolved] Dynamic Page Title

Home Forums Support Dynamic Page Title

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #226165
    Juergen

    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

    #226259
    Tom
    Lead Developer
    Lead Developer

    Hi 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 πŸ™‚

    #226456
    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

    #226521
    Tom
    Lead Developer
    Lead Developer

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

    #227055
    Juergen

    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

    #227058
    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

    #227095
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #227305
    Juergen

    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

    #227373
    Tom
    Lead Developer
    Lead Developer

    That’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 πŸ™‚

    #228101
    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

    #228134
    Tom
    Lead Developer
    Lead Developer

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

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.