简体   繁体   中英

Wordpress: Trying to call get_permalink in widget definition - throws error

The commented line below throws an error.

class Overall_Travel_Times_Widget extends WP_Widget {
    var $title       = 'Travel Times Widget';
    //var $title_link  = get_permalink( get_page_by_path( 'delays' ) );

How can I access the standard wordpress functionality from inside the widget definition?

I tested your code, it was outputting parse error "unexpected var"

    Parse error: syntax error, unexpected 'var' (T_VAR) 

I remove var keyword in front of your variables and it worked:

 $title       = 'Travel Times Widget';
 $title_link  = get_permalink( get_page_by_path( 'delays' ) );

So after removing 'var' which you have in front of both variables, your code will work fine. As I tested it provided me the link for the page with the slug I provided.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM