get_permalink not working in WordPress template file

I an newbie in PHP and I have the following in a template file.

$url = get_permalink(get_page_by_title('Main'));

But the above line gives me an error ..

Read More
Fatal error: Call to undefined function get_permalink() in C:wampwwwwordpresswp-contentthemestwentysixteenhandleLogin.php

I tried including the file link-template at the top by using the below line but it doesn’t find the file either.

include_once 'wp-includes/link-template.php';

I googled but everyone seems to have it working .. those who complained were having typos in the function name which are not my cases.

Any help will be appreciated. Thanks.

Related posts

1 comment

  1. I know this is a very old post. But posting if anyone comes looking for answers like me.

    After requiring, wp-load.php add below,

    require_once ABSPATH . WPINC . '/class-wp-rewrite.php';
    require_once ABSPATH . WPINC . '/link-template.php';
    require_once ABSPATH . WPINC . '/post.php';
    require_once ABSPATH . WPINC . '/class-wp-post.php';
    require_once ABSPATH . WPINC . '/category-template.php';
    require_once ABSPATH . WPINC . '/taxonomy.php';
    require_once ABSPATH . WPINC . '/l10n.php';
    require_once ABSPATH . WPINC . '/formatting.php';
    

Comments are closed.