Why the_title() filter is also applied in menu title?











up vote
9
down vote

favorite
3












I have created below function to hide page title . But when i execute it it also hide
menu name also. Can any one please help on that it will be highly appreciated.



function wsits_post_page_title( $title ) {
if( is_admin())

return $title;

$selected_type = get_option('wsits_page_show_hide');

if(!is_array($selected_type)) return $title;

if ( ( in_array(get_post_type(), $selected_type ) ) && get_option('wsits_page_show_hide') )
{
$title = '';
}
return $title;
}
add_filter( 'the_title', array($this, 'wsits_post_page_title') );









share|improve this question


















  • 6




    Because menu items also have titles and they need to be filtered :). If this is your theme, you can remove the filter before displaying the menu and then adding it again. Alternatively you can do the opposite and add the filter only when you need it.
    – Nikola Ivanov Nikolov
    Nov 19 '12 at 15:11






  • 2




    How would someone go about removing a filter and adding it back after displaying the menu title?
    – Greg L
    Jan 22 '14 at 0:17















up vote
9
down vote

favorite
3












I have created below function to hide page title . But when i execute it it also hide
menu name also. Can any one please help on that it will be highly appreciated.



function wsits_post_page_title( $title ) {
if( is_admin())

return $title;

$selected_type = get_option('wsits_page_show_hide');

if(!is_array($selected_type)) return $title;

if ( ( in_array(get_post_type(), $selected_type ) ) && get_option('wsits_page_show_hide') )
{
$title = '';
}
return $title;
}
add_filter( 'the_title', array($this, 'wsits_post_page_title') );









share|improve this question


















  • 6




    Because menu items also have titles and they need to be filtered :). If this is your theme, you can remove the filter before displaying the menu and then adding it again. Alternatively you can do the opposite and add the filter only when you need it.
    – Nikola Ivanov Nikolov
    Nov 19 '12 at 15:11






  • 2




    How would someone go about removing a filter and adding it back after displaying the menu title?
    – Greg L
    Jan 22 '14 at 0:17













up vote
9
down vote

favorite
3









up vote
9
down vote

favorite
3






3





I have created below function to hide page title . But when i execute it it also hide
menu name also. Can any one please help on that it will be highly appreciated.



function wsits_post_page_title( $title ) {
if( is_admin())

return $title;

$selected_type = get_option('wsits_page_show_hide');

if(!is_array($selected_type)) return $title;

if ( ( in_array(get_post_type(), $selected_type ) ) && get_option('wsits_page_show_hide') )
{
$title = '';
}
return $title;
}
add_filter( 'the_title', array($this, 'wsits_post_page_title') );









share|improve this question













I have created below function to hide page title . But when i execute it it also hide
menu name also. Can any one please help on that it will be highly appreciated.



function wsits_post_page_title( $title ) {
if( is_admin())

return $title;

$selected_type = get_option('wsits_page_show_hide');

if(!is_array($selected_type)) return $title;

if ( ( in_array(get_post_type(), $selected_type ) ) && get_option('wsits_page_show_hide') )
{
$title = '';
}
return $title;
}
add_filter( 'the_title', array($this, 'wsits_post_page_title') );






php wordpress filter themes wrap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '12 at 15:08









softsdev

1,23811124




1,23811124








  • 6




    Because menu items also have titles and they need to be filtered :). If this is your theme, you can remove the filter before displaying the menu and then adding it again. Alternatively you can do the opposite and add the filter only when you need it.
    – Nikola Ivanov Nikolov
    Nov 19 '12 at 15:11






  • 2




    How would someone go about removing a filter and adding it back after displaying the menu title?
    – Greg L
    Jan 22 '14 at 0:17














  • 6




    Because menu items also have titles and they need to be filtered :). If this is your theme, you can remove the filter before displaying the menu and then adding it again. Alternatively you can do the opposite and add the filter only when you need it.
    – Nikola Ivanov Nikolov
    Nov 19 '12 at 15:11






  • 2




    How would someone go about removing a filter and adding it back after displaying the menu title?
    – Greg L
    Jan 22 '14 at 0:17








6




6




Because menu items also have titles and they need to be filtered :). If this is your theme, you can remove the filter before displaying the menu and then adding it again. Alternatively you can do the opposite and add the filter only when you need it.
– Nikola Ivanov Nikolov
Nov 19 '12 at 15:11




Because menu items also have titles and they need to be filtered :). If this is your theme, you can remove the filter before displaying the menu and then adding it again. Alternatively you can do the opposite and add the filter only when you need it.
– Nikola Ivanov Nikolov
Nov 19 '12 at 15:11




2




2




How would someone go about removing a filter and adding it back after displaying the menu title?
– Greg L
Jan 22 '14 at 0:17




How would someone go about removing a filter and adding it back after displaying the menu title?
– Greg L
Jan 22 '14 at 0:17












5 Answers
5






active

oldest

votes

















up vote
12
down vote



accepted










Nikola is correct:




Because menu items also have titles and they need to be filtered :).




To make this only call in the posts, and not in menus, you can add a check for in_the_loop() - if it is true, you're in a post.



So change the first line in the function to:



if( is_admin() || !in_the_loop() )



and all should be well.






share|improve this answer





















  • thank you verymuch
    – softsdev
    Nov 20 '12 at 5:28










  • @Paul This is not working for the widget containing custom menu.
    – Faiyaz Alam
    Mar 20 '17 at 7:35


















up vote
4
down vote













You can do something like that :



In your function.php :



add_filter( 'the_title', 'ze_title');
function ze_title($a) {
global $dontTouch;
if(!$dontTouch && !is_admin())
$a = someChange($a);
return $a;
}


In your template :



$dontTouch = 1;
wp_nav_menu( array('menu' => 'MyMenu') );
$dontTouch = 0;





share|improve this answer



















  • 2




    Not clean, but simple and does work.
    – sglessard
    Jan 11 '14 at 16:30


















up vote
4
down vote













It's a bit of a hack but you can solve this by adding your action to loop_start.



function make_custom_title( $title, $id ) {
// Your Code Here
}

function set_custom_title() {
add_filter( 'the_title', 'make_custom_title', 10, 2 );
}

add_action( 'loop_start', 'set_custom_title' );


By embedding the_title filter inside of a loop_start action, we avoid overwriting the menu title attributes.






share|improve this answer




























    up vote
    1
    down vote













    Posting this answer because it was the search result I ended up clicking on while searching about targeting the filter hook the_title while ignoring the filter effect for navigation items.



    I was working on a section in a theme which I wanted to add buttons to the page title within the heading one tag.



    It looked similar to this:



    <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title ) . '</h1>'.PHP_EOL; ?>


    I was then "hooking in" like this:



    add_filter( 'the_title', 'my_callback_function' );


    However, the above targets literally everything which calls the_title filter hook, and this includes navigation items.



    I changed the filter hook definition like this:



    <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title, $post->ID, true ) . '</h1>'.PHP_EOL; ?>


    Pretty much every call to the_title filter passes parameter 1 as the $post->post_title and parameter 2 as the $post->ID. Search the WordPress core code for apply_filters( 'the_title'* and you'll see for yourself.



    So I decided to add a third parameter for situations where I want to target specific items which call the_title filter. This way, I can still receive the benefit of all callbacks which apply to the_title filter hook by default, while also having the ability to semi-uniquely target items that use the_title filter hook with the third parameter.



    It's a simple boolean parameter:



    /**
    * @param String $title
    * @param Int $object_id
    * @param bool $theme
    *
    * @return mixed
    */
    function filter_the_title( String $title = null, Int $object_id = null, Bool $theme = false ) {

    if( ! $object_id ){
    return $title;
    }

    if( ! $theme ){
    return $title;
    }

    // your code here...

    return $title;

    }

    add_filter( 'the_title', 'filter_the_title', 10, 3 );


    Label the variables however you want. This is what worked for me, and it does exactly what I need it to do. This answer may not be 100% relevant to the question asked, but this is where I arrived while searching to solve this problem. Hope this helps someone in a similar situation.






    share|improve this answer




























      up vote
      0
      down vote













      The global $dontTouch; solution didn't work for me for some reason. So I simply removed the filter around the menu thus in header.php:



      remove_filter( 'the_title', 'change_title' );
      get_template_part( 'template-parts/navigation/navigation', 'top' );
      add_filter( 'the_title', 'change_title' );


      And all is well.






      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',
        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%2f13456521%2fwhy-the-title-filter-is-also-applied-in-menu-title%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        12
        down vote



        accepted










        Nikola is correct:




        Because menu items also have titles and they need to be filtered :).




        To make this only call in the posts, and not in menus, you can add a check for in_the_loop() - if it is true, you're in a post.



        So change the first line in the function to:



        if( is_admin() || !in_the_loop() )



        and all should be well.






        share|improve this answer





















        • thank you verymuch
          – softsdev
          Nov 20 '12 at 5:28










        • @Paul This is not working for the widget containing custom menu.
          – Faiyaz Alam
          Mar 20 '17 at 7:35















        up vote
        12
        down vote



        accepted










        Nikola is correct:




        Because menu items also have titles and they need to be filtered :).




        To make this only call in the posts, and not in menus, you can add a check for in_the_loop() - if it is true, you're in a post.



        So change the first line in the function to:



        if( is_admin() || !in_the_loop() )



        and all should be well.






        share|improve this answer





















        • thank you verymuch
          – softsdev
          Nov 20 '12 at 5:28










        • @Paul This is not working for the widget containing custom menu.
          – Faiyaz Alam
          Mar 20 '17 at 7:35













        up vote
        12
        down vote



        accepted







        up vote
        12
        down vote



        accepted






        Nikola is correct:




        Because menu items also have titles and they need to be filtered :).




        To make this only call in the posts, and not in menus, you can add a check for in_the_loop() - if it is true, you're in a post.



        So change the first line in the function to:



        if( is_admin() || !in_the_loop() )



        and all should be well.






        share|improve this answer












        Nikola is correct:




        Because menu items also have titles and they need to be filtered :).




        To make this only call in the posts, and not in menus, you can add a check for in_the_loop() - if it is true, you're in a post.



        So change the first line in the function to:



        if( is_admin() || !in_the_loop() )



        and all should be well.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '12 at 15:43









        Paul Gregory

        1,6131624




        1,6131624












        • thank you verymuch
          – softsdev
          Nov 20 '12 at 5:28










        • @Paul This is not working for the widget containing custom menu.
          – Faiyaz Alam
          Mar 20 '17 at 7:35


















        • thank you verymuch
          – softsdev
          Nov 20 '12 at 5:28










        • @Paul This is not working for the widget containing custom menu.
          – Faiyaz Alam
          Mar 20 '17 at 7:35
















        thank you verymuch
        – softsdev
        Nov 20 '12 at 5:28




        thank you verymuch
        – softsdev
        Nov 20 '12 at 5:28












        @Paul This is not working for the widget containing custom menu.
        – Faiyaz Alam
        Mar 20 '17 at 7:35




        @Paul This is not working for the widget containing custom menu.
        – Faiyaz Alam
        Mar 20 '17 at 7:35












        up vote
        4
        down vote













        You can do something like that :



        In your function.php :



        add_filter( 'the_title', 'ze_title');
        function ze_title($a) {
        global $dontTouch;
        if(!$dontTouch && !is_admin())
        $a = someChange($a);
        return $a;
        }


        In your template :



        $dontTouch = 1;
        wp_nav_menu( array('menu' => 'MyMenu') );
        $dontTouch = 0;





        share|improve this answer



















        • 2




          Not clean, but simple and does work.
          – sglessard
          Jan 11 '14 at 16:30















        up vote
        4
        down vote













        You can do something like that :



        In your function.php :



        add_filter( 'the_title', 'ze_title');
        function ze_title($a) {
        global $dontTouch;
        if(!$dontTouch && !is_admin())
        $a = someChange($a);
        return $a;
        }


        In your template :



        $dontTouch = 1;
        wp_nav_menu( array('menu' => 'MyMenu') );
        $dontTouch = 0;





        share|improve this answer



















        • 2




          Not clean, but simple and does work.
          – sglessard
          Jan 11 '14 at 16:30













        up vote
        4
        down vote










        up vote
        4
        down vote









        You can do something like that :



        In your function.php :



        add_filter( 'the_title', 'ze_title');
        function ze_title($a) {
        global $dontTouch;
        if(!$dontTouch && !is_admin())
        $a = someChange($a);
        return $a;
        }


        In your template :



        $dontTouch = 1;
        wp_nav_menu( array('menu' => 'MyMenu') );
        $dontTouch = 0;





        share|improve this answer














        You can do something like that :



        In your function.php :



        add_filter( 'the_title', 'ze_title');
        function ze_title($a) {
        global $dontTouch;
        if(!$dontTouch && !is_admin())
        $a = someChange($a);
        return $a;
        }


        In your template :



        $dontTouch = 1;
        wp_nav_menu( array('menu' => 'MyMenu') );
        $dontTouch = 0;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 13 '14 at 11:21

























        answered Dec 11 '12 at 22:09









        Cyril

        1,56021723




        1,56021723








        • 2




          Not clean, but simple and does work.
          – sglessard
          Jan 11 '14 at 16:30














        • 2




          Not clean, but simple and does work.
          – sglessard
          Jan 11 '14 at 16:30








        2




        2




        Not clean, but simple and does work.
        – sglessard
        Jan 11 '14 at 16:30




        Not clean, but simple and does work.
        – sglessard
        Jan 11 '14 at 16:30










        up vote
        4
        down vote













        It's a bit of a hack but you can solve this by adding your action to loop_start.



        function make_custom_title( $title, $id ) {
        // Your Code Here
        }

        function set_custom_title() {
        add_filter( 'the_title', 'make_custom_title', 10, 2 );
        }

        add_action( 'loop_start', 'set_custom_title' );


        By embedding the_title filter inside of a loop_start action, we avoid overwriting the menu title attributes.






        share|improve this answer

























          up vote
          4
          down vote













          It's a bit of a hack but you can solve this by adding your action to loop_start.



          function make_custom_title( $title, $id ) {
          // Your Code Here
          }

          function set_custom_title() {
          add_filter( 'the_title', 'make_custom_title', 10, 2 );
          }

          add_action( 'loop_start', 'set_custom_title' );


          By embedding the_title filter inside of a loop_start action, we avoid overwriting the menu title attributes.






          share|improve this answer























            up vote
            4
            down vote










            up vote
            4
            down vote









            It's a bit of a hack but you can solve this by adding your action to loop_start.



            function make_custom_title( $title, $id ) {
            // Your Code Here
            }

            function set_custom_title() {
            add_filter( 'the_title', 'make_custom_title', 10, 2 );
            }

            add_action( 'loop_start', 'set_custom_title' );


            By embedding the_title filter inside of a loop_start action, we avoid overwriting the menu title attributes.






            share|improve this answer












            It's a bit of a hack but you can solve this by adding your action to loop_start.



            function make_custom_title( $title, $id ) {
            // Your Code Here
            }

            function set_custom_title() {
            add_filter( 'the_title', 'make_custom_title', 10, 2 );
            }

            add_action( 'loop_start', 'set_custom_title' );


            By embedding the_title filter inside of a loop_start action, we avoid overwriting the menu title attributes.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 16 '14 at 8:52









            Imperative

            509617




            509617






















                up vote
                1
                down vote













                Posting this answer because it was the search result I ended up clicking on while searching about targeting the filter hook the_title while ignoring the filter effect for navigation items.



                I was working on a section in a theme which I wanted to add buttons to the page title within the heading one tag.



                It looked similar to this:



                <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title ) . '</h1>'.PHP_EOL; ?>


                I was then "hooking in" like this:



                add_filter( 'the_title', 'my_callback_function' );


                However, the above targets literally everything which calls the_title filter hook, and this includes navigation items.



                I changed the filter hook definition like this:



                <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title, $post->ID, true ) . '</h1>'.PHP_EOL; ?>


                Pretty much every call to the_title filter passes parameter 1 as the $post->post_title and parameter 2 as the $post->ID. Search the WordPress core code for apply_filters( 'the_title'* and you'll see for yourself.



                So I decided to add a third parameter for situations where I want to target specific items which call the_title filter. This way, I can still receive the benefit of all callbacks which apply to the_title filter hook by default, while also having the ability to semi-uniquely target items that use the_title filter hook with the third parameter.



                It's a simple boolean parameter:



                /**
                * @param String $title
                * @param Int $object_id
                * @param bool $theme
                *
                * @return mixed
                */
                function filter_the_title( String $title = null, Int $object_id = null, Bool $theme = false ) {

                if( ! $object_id ){
                return $title;
                }

                if( ! $theme ){
                return $title;
                }

                // your code here...

                return $title;

                }

                add_filter( 'the_title', 'filter_the_title', 10, 3 );


                Label the variables however you want. This is what worked for me, and it does exactly what I need it to do. This answer may not be 100% relevant to the question asked, but this is where I arrived while searching to solve this problem. Hope this helps someone in a similar situation.






                share|improve this answer

























                  up vote
                  1
                  down vote













                  Posting this answer because it was the search result I ended up clicking on while searching about targeting the filter hook the_title while ignoring the filter effect for navigation items.



                  I was working on a section in a theme which I wanted to add buttons to the page title within the heading one tag.



                  It looked similar to this:



                  <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title ) . '</h1>'.PHP_EOL; ?>


                  I was then "hooking in" like this:



                  add_filter( 'the_title', 'my_callback_function' );


                  However, the above targets literally everything which calls the_title filter hook, and this includes navigation items.



                  I changed the filter hook definition like this:



                  <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title, $post->ID, true ) . '</h1>'.PHP_EOL; ?>


                  Pretty much every call to the_title filter passes parameter 1 as the $post->post_title and parameter 2 as the $post->ID. Search the WordPress core code for apply_filters( 'the_title'* and you'll see for yourself.



                  So I decided to add a third parameter for situations where I want to target specific items which call the_title filter. This way, I can still receive the benefit of all callbacks which apply to the_title filter hook by default, while also having the ability to semi-uniquely target items that use the_title filter hook with the third parameter.



                  It's a simple boolean parameter:



                  /**
                  * @param String $title
                  * @param Int $object_id
                  * @param bool $theme
                  *
                  * @return mixed
                  */
                  function filter_the_title( String $title = null, Int $object_id = null, Bool $theme = false ) {

                  if( ! $object_id ){
                  return $title;
                  }

                  if( ! $theme ){
                  return $title;
                  }

                  // your code here...

                  return $title;

                  }

                  add_filter( 'the_title', 'filter_the_title', 10, 3 );


                  Label the variables however you want. This is what worked for me, and it does exactly what I need it to do. This answer may not be 100% relevant to the question asked, but this is where I arrived while searching to solve this problem. Hope this helps someone in a similar situation.






                  share|improve this answer























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    Posting this answer because it was the search result I ended up clicking on while searching about targeting the filter hook the_title while ignoring the filter effect for navigation items.



                    I was working on a section in a theme which I wanted to add buttons to the page title within the heading one tag.



                    It looked similar to this:



                    <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title ) . '</h1>'.PHP_EOL; ?>


                    I was then "hooking in" like this:



                    add_filter( 'the_title', 'my_callback_function' );


                    However, the above targets literally everything which calls the_title filter hook, and this includes navigation items.



                    I changed the filter hook definition like this:



                    <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title, $post->ID, true ) . '</h1>'.PHP_EOL; ?>


                    Pretty much every call to the_title filter passes parameter 1 as the $post->post_title and parameter 2 as the $post->ID. Search the WordPress core code for apply_filters( 'the_title'* and you'll see for yourself.



                    So I decided to add a third parameter for situations where I want to target specific items which call the_title filter. This way, I can still receive the benefit of all callbacks which apply to the_title filter hook by default, while also having the ability to semi-uniquely target items that use the_title filter hook with the third parameter.



                    It's a simple boolean parameter:



                    /**
                    * @param String $title
                    * @param Int $object_id
                    * @param bool $theme
                    *
                    * @return mixed
                    */
                    function filter_the_title( String $title = null, Int $object_id = null, Bool $theme = false ) {

                    if( ! $object_id ){
                    return $title;
                    }

                    if( ! $theme ){
                    return $title;
                    }

                    // your code here...

                    return $title;

                    }

                    add_filter( 'the_title', 'filter_the_title', 10, 3 );


                    Label the variables however you want. This is what worked for me, and it does exactly what I need it to do. This answer may not be 100% relevant to the question asked, but this is where I arrived while searching to solve this problem. Hope this helps someone in a similar situation.






                    share|improve this answer












                    Posting this answer because it was the search result I ended up clicking on while searching about targeting the filter hook the_title while ignoring the filter effect for navigation items.



                    I was working on a section in a theme which I wanted to add buttons to the page title within the heading one tag.



                    It looked similar to this:



                    <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title ) . '</h1>'.PHP_EOL; ?>


                    I was then "hooking in" like this:



                    add_filter( 'the_title', 'my_callback_function' );


                    However, the above targets literally everything which calls the_title filter hook, and this includes navigation items.



                    I changed the filter hook definition like this:



                    <?php echo '<h1>' . apply_filters( 'the_title', $post->post_title, $post->ID, true ) . '</h1>'.PHP_EOL; ?>


                    Pretty much every call to the_title filter passes parameter 1 as the $post->post_title and parameter 2 as the $post->ID. Search the WordPress core code for apply_filters( 'the_title'* and you'll see for yourself.



                    So I decided to add a third parameter for situations where I want to target specific items which call the_title filter. This way, I can still receive the benefit of all callbacks which apply to the_title filter hook by default, while also having the ability to semi-uniquely target items that use the_title filter hook with the third parameter.



                    It's a simple boolean parameter:



                    /**
                    * @param String $title
                    * @param Int $object_id
                    * @param bool $theme
                    *
                    * @return mixed
                    */
                    function filter_the_title( String $title = null, Int $object_id = null, Bool $theme = false ) {

                    if( ! $object_id ){
                    return $title;
                    }

                    if( ! $theme ){
                    return $title;
                    }

                    // your code here...

                    return $title;

                    }

                    add_filter( 'the_title', 'filter_the_title', 10, 3 );


                    Label the variables however you want. This is what worked for me, and it does exactly what I need it to do. This answer may not be 100% relevant to the question asked, but this is where I arrived while searching to solve this problem. Hope this helps someone in a similar situation.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 23 '17 at 23:01









                    Michael Ecklund

                    48411029




                    48411029






















                        up vote
                        0
                        down vote













                        The global $dontTouch; solution didn't work for me for some reason. So I simply removed the filter around the menu thus in header.php:



                        remove_filter( 'the_title', 'change_title' );
                        get_template_part( 'template-parts/navigation/navigation', 'top' );
                        add_filter( 'the_title', 'change_title' );


                        And all is well.






                        share|improve this answer

























                          up vote
                          0
                          down vote













                          The global $dontTouch; solution didn't work for me for some reason. So I simply removed the filter around the menu thus in header.php:



                          remove_filter( 'the_title', 'change_title' );
                          get_template_part( 'template-parts/navigation/navigation', 'top' );
                          add_filter( 'the_title', 'change_title' );


                          And all is well.






                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            The global $dontTouch; solution didn't work for me for some reason. So I simply removed the filter around the menu thus in header.php:



                            remove_filter( 'the_title', 'change_title' );
                            get_template_part( 'template-parts/navigation/navigation', 'top' );
                            add_filter( 'the_title', 'change_title' );


                            And all is well.






                            share|improve this answer












                            The global $dontTouch; solution didn't work for me for some reason. So I simply removed the filter around the menu thus in header.php:



                            remove_filter( 'the_title', 'change_title' );
                            get_template_part( 'template-parts/navigation/navigation', 'top' );
                            add_filter( 'the_title', 'change_title' );


                            And all is well.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 20 at 15:34









                            arathra

                            418




                            418






























                                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.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • 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%2f13456521%2fwhy-the-title-filter-is-also-applied-in-menu-title%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

                                Feedback on college project

                                Futebolista

                                Albești (Vaslui)