WooCommerce: Override the title set to the browsers tab in my account page












1















I'm currently trying to change the title set in the browsers tab when visiting the My Account page in WooCommerce.



When I go for example to the Orders page the tab is still named My Account and this is not so nice. It should always has the name of the endpoint / account_menu_items. I've tried this here but this changes only the title on the menu content at the top left:



/**
* Change title for menu items
*/
add_filter( 'the_title', 'custom_account_endpoint_titles' );
function custom_account_endpoint_titles( $title ) {
global $wp_query;

if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {
return 'Orders';
}

return $title;
}


Screenshot:



enter image description here










share|improve this question


















  • 1





    Which WordPress theme are you using?

    – Mr. Me
    Dec 28 '18 at 19:55











  • @Mr.Me I'm using Divi

    – Mr. Jo
    Dec 28 '18 at 22:08
















1















I'm currently trying to change the title set in the browsers tab when visiting the My Account page in WooCommerce.



When I go for example to the Orders page the tab is still named My Account and this is not so nice. It should always has the name of the endpoint / account_menu_items. I've tried this here but this changes only the title on the menu content at the top left:



/**
* Change title for menu items
*/
add_filter( 'the_title', 'custom_account_endpoint_titles' );
function custom_account_endpoint_titles( $title ) {
global $wp_query;

if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {
return 'Orders';
}

return $title;
}


Screenshot:



enter image description here










share|improve this question


















  • 1





    Which WordPress theme are you using?

    – Mr. Me
    Dec 28 '18 at 19:55











  • @Mr.Me I'm using Divi

    – Mr. Jo
    Dec 28 '18 at 22:08














1












1








1








I'm currently trying to change the title set in the browsers tab when visiting the My Account page in WooCommerce.



When I go for example to the Orders page the tab is still named My Account and this is not so nice. It should always has the name of the endpoint / account_menu_items. I've tried this here but this changes only the title on the menu content at the top left:



/**
* Change title for menu items
*/
add_filter( 'the_title', 'custom_account_endpoint_titles' );
function custom_account_endpoint_titles( $title ) {
global $wp_query;

if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {
return 'Orders';
}

return $title;
}


Screenshot:



enter image description here










share|improve this question














I'm currently trying to change the title set in the browsers tab when visiting the My Account page in WooCommerce.



When I go for example to the Orders page the tab is still named My Account and this is not so nice. It should always has the name of the endpoint / account_menu_items. I've tried this here but this changes only the title on the menu content at the top left:



/**
* Change title for menu items
*/
add_filter( 'the_title', 'custom_account_endpoint_titles' );
function custom_account_endpoint_titles( $title ) {
global $wp_query;

if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {
return 'Orders';
}

return $title;
}


Screenshot:



enter image description here







php wordpress woocommerce






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 28 '18 at 19:44









Mr. JoMr. Jo

660114




660114








  • 1





    Which WordPress theme are you using?

    – Mr. Me
    Dec 28 '18 at 19:55











  • @Mr.Me I'm using Divi

    – Mr. Jo
    Dec 28 '18 at 22:08














  • 1





    Which WordPress theme are you using?

    – Mr. Me
    Dec 28 '18 at 19:55











  • @Mr.Me I'm using Divi

    – Mr. Jo
    Dec 28 '18 at 22:08








1




1





Which WordPress theme are you using?

– Mr. Me
Dec 28 '18 at 19:55





Which WordPress theme are you using?

– Mr. Me
Dec 28 '18 at 19:55













@Mr.Me I'm using Divi

– Mr. Jo
Dec 28 '18 at 22:08





@Mr.Me I'm using Divi

– Mr. Jo
Dec 28 '18 at 22:08












2 Answers
2






active

oldest

votes


















1














Try using the pre_get_document_title filter instead as this allows you to modify it before it's rendered.



Note theat the $title_pieces is actually an array that looks like



array (
'title' => 'title example',
'tagline' => 'just another wordpress blog'
}


So you need to do it like this



add_filter( 'pre_get_document_title', 'custom_account_endpoint_titles' );

function custom_account_endpoint_titles($title_pieces) {

global $wp_query;

if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {

$title_pieces['title'] = 'Orders';
//$title_pieces['tagline'] = 'Your tag line'; Set a tag line if you want to

return $title_pieces;
}

return $title_pieces;

}


Also, make sure to dump the value of $wp_query->query_vars['orders'] to ensure its the value you're actually looking for






share|improve this answer


























  • Added this but it don't works. Still My Account in the tab :(

    – Mr. Jo
    Dec 28 '18 at 22:11






  • 1





    delete the global $wp_query;, delete the if statement and set $title = 'test'. What about then? Make sure to clear cache aswell

    – Ashley Brown
    Dec 28 '18 at 22:21













  • Still not working. Caching is disabled.

    – Mr. Jo
    Dec 28 '18 at 22:25













  • what version of WP are you using?

    – Ashley Brown
    Dec 28 '18 at 22:27











  • Using version 4.9.9 with the Divi Theme and Yoast SEO installed.

    – Mr. Jo
    Dec 28 '18 at 22:29



















1














I've finally found the filter and the way to change it:



/**
* Override woocommerce account endpoint titles in the browser tab
*/
add_filter( 'wpseo_title', 'woocommerce_endpoint_titles' );
function woocommerce_endpoint_titles( $title ) {
$sep = ' – ';
$sitetitle = get_bloginfo();

if ( is_wc_endpoint_url( 'orders' ) ) {
$title = 'Bestellungen' . $sep . $sitetitle;
} elseif ( is_wc_endpoint_url( 'view-order' ) ) {
$title = 'Bestellung' . $sep . $sitetitle;
}

return $title;
}


If you created your own endpoints in WooCommerce you can use this filter too but you need to register your custom endpoints first. You can do it this way:



/**
* Add custom menu items to wc query vars so that we can use is_wc_endpoint_url()
*/
add_filter( 'woocommerce_get_query_vars', 'add_items_to_query_vars' );
function add_items_to_query_vars( $vars ) {

foreach ( [ 'custom-endpoint-1', 'custom-endpoint-2' ] as $e ) {
$vars[ $e ] = $e;
}

return $vars;
}


I hope this helps someone.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963593%2fwoocommerce-override-the-title-set-to-the-browsers-tab-in-my-account-page%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Try using the pre_get_document_title filter instead as this allows you to modify it before it's rendered.



    Note theat the $title_pieces is actually an array that looks like



    array (
    'title' => 'title example',
    'tagline' => 'just another wordpress blog'
    }


    So you need to do it like this



    add_filter( 'pre_get_document_title', 'custom_account_endpoint_titles' );

    function custom_account_endpoint_titles($title_pieces) {

    global $wp_query;

    if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {

    $title_pieces['title'] = 'Orders';
    //$title_pieces['tagline'] = 'Your tag line'; Set a tag line if you want to

    return $title_pieces;
    }

    return $title_pieces;

    }


    Also, make sure to dump the value of $wp_query->query_vars['orders'] to ensure its the value you're actually looking for






    share|improve this answer


























    • Added this but it don't works. Still My Account in the tab :(

      – Mr. Jo
      Dec 28 '18 at 22:11






    • 1





      delete the global $wp_query;, delete the if statement and set $title = 'test'. What about then? Make sure to clear cache aswell

      – Ashley Brown
      Dec 28 '18 at 22:21













    • Still not working. Caching is disabled.

      – Mr. Jo
      Dec 28 '18 at 22:25













    • what version of WP are you using?

      – Ashley Brown
      Dec 28 '18 at 22:27











    • Using version 4.9.9 with the Divi Theme and Yoast SEO installed.

      – Mr. Jo
      Dec 28 '18 at 22:29
















    1














    Try using the pre_get_document_title filter instead as this allows you to modify it before it's rendered.



    Note theat the $title_pieces is actually an array that looks like



    array (
    'title' => 'title example',
    'tagline' => 'just another wordpress blog'
    }


    So you need to do it like this



    add_filter( 'pre_get_document_title', 'custom_account_endpoint_titles' );

    function custom_account_endpoint_titles($title_pieces) {

    global $wp_query;

    if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {

    $title_pieces['title'] = 'Orders';
    //$title_pieces['tagline'] = 'Your tag line'; Set a tag line if you want to

    return $title_pieces;
    }

    return $title_pieces;

    }


    Also, make sure to dump the value of $wp_query->query_vars['orders'] to ensure its the value you're actually looking for






    share|improve this answer


























    • Added this but it don't works. Still My Account in the tab :(

      – Mr. Jo
      Dec 28 '18 at 22:11






    • 1





      delete the global $wp_query;, delete the if statement and set $title = 'test'. What about then? Make sure to clear cache aswell

      – Ashley Brown
      Dec 28 '18 at 22:21













    • Still not working. Caching is disabled.

      – Mr. Jo
      Dec 28 '18 at 22:25













    • what version of WP are you using?

      – Ashley Brown
      Dec 28 '18 at 22:27











    • Using version 4.9.9 with the Divi Theme and Yoast SEO installed.

      – Mr. Jo
      Dec 28 '18 at 22:29














    1












    1








    1







    Try using the pre_get_document_title filter instead as this allows you to modify it before it's rendered.



    Note theat the $title_pieces is actually an array that looks like



    array (
    'title' => 'title example',
    'tagline' => 'just another wordpress blog'
    }


    So you need to do it like this



    add_filter( 'pre_get_document_title', 'custom_account_endpoint_titles' );

    function custom_account_endpoint_titles($title_pieces) {

    global $wp_query;

    if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {

    $title_pieces['title'] = 'Orders';
    //$title_pieces['tagline'] = 'Your tag line'; Set a tag line if you want to

    return $title_pieces;
    }

    return $title_pieces;

    }


    Also, make sure to dump the value of $wp_query->query_vars['orders'] to ensure its the value you're actually looking for






    share|improve this answer















    Try using the pre_get_document_title filter instead as this allows you to modify it before it's rendered.



    Note theat the $title_pieces is actually an array that looks like



    array (
    'title' => 'title example',
    'tagline' => 'just another wordpress blog'
    }


    So you need to do it like this



    add_filter( 'pre_get_document_title', 'custom_account_endpoint_titles' );

    function custom_account_endpoint_titles($title_pieces) {

    global $wp_query;

    if ( in_the_loop() && isset( $wp_query->query_vars['orders'] ) ) {

    $title_pieces['title'] = 'Orders';
    //$title_pieces['tagline'] = 'Your tag line'; Set a tag line if you want to

    return $title_pieces;
    }

    return $title_pieces;

    }


    Also, make sure to dump the value of $wp_query->query_vars['orders'] to ensure its the value you're actually looking for







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 28 '18 at 22:51

























    answered Dec 28 '18 at 19:55









    Ashley BrownAshley Brown

    3,07062043




    3,07062043













    • Added this but it don't works. Still My Account in the tab :(

      – Mr. Jo
      Dec 28 '18 at 22:11






    • 1





      delete the global $wp_query;, delete the if statement and set $title = 'test'. What about then? Make sure to clear cache aswell

      – Ashley Brown
      Dec 28 '18 at 22:21













    • Still not working. Caching is disabled.

      – Mr. Jo
      Dec 28 '18 at 22:25













    • what version of WP are you using?

      – Ashley Brown
      Dec 28 '18 at 22:27











    • Using version 4.9.9 with the Divi Theme and Yoast SEO installed.

      – Mr. Jo
      Dec 28 '18 at 22:29



















    • Added this but it don't works. Still My Account in the tab :(

      – Mr. Jo
      Dec 28 '18 at 22:11






    • 1





      delete the global $wp_query;, delete the if statement and set $title = 'test'. What about then? Make sure to clear cache aswell

      – Ashley Brown
      Dec 28 '18 at 22:21













    • Still not working. Caching is disabled.

      – Mr. Jo
      Dec 28 '18 at 22:25













    • what version of WP are you using?

      – Ashley Brown
      Dec 28 '18 at 22:27











    • Using version 4.9.9 with the Divi Theme and Yoast SEO installed.

      – Mr. Jo
      Dec 28 '18 at 22:29

















    Added this but it don't works. Still My Account in the tab :(

    – Mr. Jo
    Dec 28 '18 at 22:11





    Added this but it don't works. Still My Account in the tab :(

    – Mr. Jo
    Dec 28 '18 at 22:11




    1




    1





    delete the global $wp_query;, delete the if statement and set $title = 'test'. What about then? Make sure to clear cache aswell

    – Ashley Brown
    Dec 28 '18 at 22:21







    delete the global $wp_query;, delete the if statement and set $title = 'test'. What about then? Make sure to clear cache aswell

    – Ashley Brown
    Dec 28 '18 at 22:21















    Still not working. Caching is disabled.

    – Mr. Jo
    Dec 28 '18 at 22:25







    Still not working. Caching is disabled.

    – Mr. Jo
    Dec 28 '18 at 22:25















    what version of WP are you using?

    – Ashley Brown
    Dec 28 '18 at 22:27





    what version of WP are you using?

    – Ashley Brown
    Dec 28 '18 at 22:27













    Using version 4.9.9 with the Divi Theme and Yoast SEO installed.

    – Mr. Jo
    Dec 28 '18 at 22:29





    Using version 4.9.9 with the Divi Theme and Yoast SEO installed.

    – Mr. Jo
    Dec 28 '18 at 22:29













    1














    I've finally found the filter and the way to change it:



    /**
    * Override woocommerce account endpoint titles in the browser tab
    */
    add_filter( 'wpseo_title', 'woocommerce_endpoint_titles' );
    function woocommerce_endpoint_titles( $title ) {
    $sep = ' – ';
    $sitetitle = get_bloginfo();

    if ( is_wc_endpoint_url( 'orders' ) ) {
    $title = 'Bestellungen' . $sep . $sitetitle;
    } elseif ( is_wc_endpoint_url( 'view-order' ) ) {
    $title = 'Bestellung' . $sep . $sitetitle;
    }

    return $title;
    }


    If you created your own endpoints in WooCommerce you can use this filter too but you need to register your custom endpoints first. You can do it this way:



    /**
    * Add custom menu items to wc query vars so that we can use is_wc_endpoint_url()
    */
    add_filter( 'woocommerce_get_query_vars', 'add_items_to_query_vars' );
    function add_items_to_query_vars( $vars ) {

    foreach ( [ 'custom-endpoint-1', 'custom-endpoint-2' ] as $e ) {
    $vars[ $e ] = $e;
    }

    return $vars;
    }


    I hope this helps someone.






    share|improve this answer




























      1














      I've finally found the filter and the way to change it:



      /**
      * Override woocommerce account endpoint titles in the browser tab
      */
      add_filter( 'wpseo_title', 'woocommerce_endpoint_titles' );
      function woocommerce_endpoint_titles( $title ) {
      $sep = ' – ';
      $sitetitle = get_bloginfo();

      if ( is_wc_endpoint_url( 'orders' ) ) {
      $title = 'Bestellungen' . $sep . $sitetitle;
      } elseif ( is_wc_endpoint_url( 'view-order' ) ) {
      $title = 'Bestellung' . $sep . $sitetitle;
      }

      return $title;
      }


      If you created your own endpoints in WooCommerce you can use this filter too but you need to register your custom endpoints first. You can do it this way:



      /**
      * Add custom menu items to wc query vars so that we can use is_wc_endpoint_url()
      */
      add_filter( 'woocommerce_get_query_vars', 'add_items_to_query_vars' );
      function add_items_to_query_vars( $vars ) {

      foreach ( [ 'custom-endpoint-1', 'custom-endpoint-2' ] as $e ) {
      $vars[ $e ] = $e;
      }

      return $vars;
      }


      I hope this helps someone.






      share|improve this answer


























        1












        1








        1







        I've finally found the filter and the way to change it:



        /**
        * Override woocommerce account endpoint titles in the browser tab
        */
        add_filter( 'wpseo_title', 'woocommerce_endpoint_titles' );
        function woocommerce_endpoint_titles( $title ) {
        $sep = ' – ';
        $sitetitle = get_bloginfo();

        if ( is_wc_endpoint_url( 'orders' ) ) {
        $title = 'Bestellungen' . $sep . $sitetitle;
        } elseif ( is_wc_endpoint_url( 'view-order' ) ) {
        $title = 'Bestellung' . $sep . $sitetitle;
        }

        return $title;
        }


        If you created your own endpoints in WooCommerce you can use this filter too but you need to register your custom endpoints first. You can do it this way:



        /**
        * Add custom menu items to wc query vars so that we can use is_wc_endpoint_url()
        */
        add_filter( 'woocommerce_get_query_vars', 'add_items_to_query_vars' );
        function add_items_to_query_vars( $vars ) {

        foreach ( [ 'custom-endpoint-1', 'custom-endpoint-2' ] as $e ) {
        $vars[ $e ] = $e;
        }

        return $vars;
        }


        I hope this helps someone.






        share|improve this answer













        I've finally found the filter and the way to change it:



        /**
        * Override woocommerce account endpoint titles in the browser tab
        */
        add_filter( 'wpseo_title', 'woocommerce_endpoint_titles' );
        function woocommerce_endpoint_titles( $title ) {
        $sep = ' – ';
        $sitetitle = get_bloginfo();

        if ( is_wc_endpoint_url( 'orders' ) ) {
        $title = 'Bestellungen' . $sep . $sitetitle;
        } elseif ( is_wc_endpoint_url( 'view-order' ) ) {
        $title = 'Bestellung' . $sep . $sitetitle;
        }

        return $title;
        }


        If you created your own endpoints in WooCommerce you can use this filter too but you need to register your custom endpoints first. You can do it this way:



        /**
        * Add custom menu items to wc query vars so that we can use is_wc_endpoint_url()
        */
        add_filter( 'woocommerce_get_query_vars', 'add_items_to_query_vars' );
        function add_items_to_query_vars( $vars ) {

        foreach ( [ 'custom-endpoint-1', 'custom-endpoint-2' ] as $e ) {
        $vars[ $e ] = $e;
        }

        return $vars;
        }


        I hope this helps someone.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 30 '18 at 1:05









        Mr. JoMr. Jo

        660114




        660114






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963593%2fwoocommerce-override-the-title-set-to-the-browsers-tab-in-my-account-page%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas