• Resolved verdonv

    (@verdonv)


    Hi,

    I was using a jQuery function to remove templates from the template menu in a page edit screen. It was working well, but seems to have stopped working with the 4.2.3 update (though perhaps that’s coincidence).

    Following is the function from my functions.php file. I sure would appreciate any thoughts.

    /* remove most page templates to keep things simple */
    function my_remove_page_template() {
        global $pagenow;
        if ( in_array( $pagenow, array( 'post-new.php', 'post.php') ) && get_post_type() == 'page' ) { ?>
            <script type="text/javascript">
                (function($){
                    $(document).ready(function(){
                        $('#page_template option[value="sidebar-content-half-page.php"]').remove();
                        $('#page_template option[value="sidebar-content-page.php"]').remove();
                        $('#page_template option[value="sitemap.php"]').remove();
                        $('#page_template option[value="full-width-page.php"]').remove();
                        $('#page_template option[value="landing-page.php"]').remove();
                        $('#page_template option[value="content-sidebar-page.php"]').remove();
                        $('#page_template option[value="content-sidebar-half-page.php"]').remove();
                        $('#page_template option[value="blog.php"]').remove();
                        $('#page_template option[value="blog-excerpt.php"]').remove();
                    })
                })(jQuery)
            </script>
        <?php
        }
    }
    add_action('admin_footer', 'my_remove_page_template', 10);

    Thanks ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter verdonv

    (@verdonv)

    Sort of resolved this… for some reason, get_post_type() was no longer returning anything in this context, so my if statement was failing. I changed get_post_type() to $_REQUEST[‘post_type’] and things started working again.

    Thread Starter verdonv

    (@verdonv)

    well, it helps so long as post_type is in the REQUEST

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘JS Function to remove templates stopped working with 4.2.3’ is closed to new replies.