Support » Fixing WordPress » Error when opening pages

  • My site just upgraded to 3.4. The home page looks fine, but when I try to open the other pages, I get Fatal error: Call to undefined function get_page_template_slug() in /home/mwlc/ on line 228

    How do I fix this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • I’m having this exact same error after upgrading to WordPress 3.4 this morning. I can’t even open the home page, actually.

    If you find a fix, or if anyone else knows the answer, please let us know!

    go to wp-includes/template.php

    Insert this chunk of code

    // in wp-includes/post-template.php
     * Get the specific template name for a page.
     * @since 3.4.0
     * @param int $id The page ID to check. Defaults to the current post, when used in the loop.
     * @return string|bool Page template filename. Returns an empty string when the default page template
     *  is in use. Returns false if the post is not a page.
    function get_page_template_slug( $post_id = null ) {
        $post = get_post( $post_id );
        if ( 'page' != $post->post_type )
            return false;
        $template = get_post_meta( $post->ID, '_wp_page_template', true );
        if ( ! $template || 'default' == $template )
            return '';
        return $template;

    After this chunk of code

    function get_page_template() {
    	$id = get_queried_object_id();
    	$template = get_page_template_slug();
    	$pagename = get_query_var('pagename');
    	if ( ! $pagename && $id ) {
    		// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
    		$post = get_queried_object();
    		$pagename = $post->post_name;
    	$templates = array();
    	if ( $template && 0 === validate_file( $template ) )
    		$templates[] = $template;
    	if ( $pagename )
    		$templates[] = "page-$pagename.php";
    	if ( $id )
    		$templates[] = "page-$id.php";
    	$templates[] = 'page.php';
    	return get_query_template( 'page', $templates );

    That’s what worked for me. Good luck!

    Moderator Jan Dembowski


    Brute Squad and Volunteer Moderator

    go to wp-includes/template.php

    Insert this chunk of code

    NO! Do not edit any files distributed with WordPress! Ever! You risk making your installation unstable, unsupportable, and prone to being hacked.

    Seriously, this is a bad idea do not do it. This is NOT a solution to any problem.

    @yachinyou, I appreciate that you are trying to help but this is just plain bad advice. Please do not recommend this solution.

    Well what do you propose, then, Jan?

    I’m having the exact same issue, but now I’m paranoid about getting it resolved. Provide a solution, please.

    Moderator Sergey Biryukov


    WordPress Dev

    The error means you have some corrupt files in your WP installation, which could be a result of an incomplete upgrade.

    A proper solution is to make sure all the files are completely uploaded. Try downloading a fresh copy of WordPress and doing a manual update.

    get_page_template_slug() is defined in wp-includes/post-template.php.



    A complete manual update is just way too time consuming and daunting for a non-technical person like me. But I agree that editing the file yourself is also risky. This time I downloaded the latest copy of wordpress and replaced the troubled file with the new one. It worked.

    I had to use this method because I had a client’s site that worked yesterday after upgrading and then suddenly today gave us that error message. When I made the changed suggested above it fixed it. Then I read down and saw the discouragement so tried instead downloading wordpress and just moving that newly downloaded template.php file but I still had the same issue so I ended up having to instead go back to the first method. Any advice here?

    site is:



    Forum Moderator

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Error when opening pages’ is closed to new replies.