Irene T.
Irene T.

Reputation: 1393

Issue with my simple custom wp plugin

i made a very simple wp plugin to do some test.. in fact i wanna grab post permalink and futured image path but every time that any post loads it gives me random results.

For example if my post is http://www.blahblahsite.com/?p=1234 my plugin will never return this url... each time it returns random e.g http://www.balhblahsite.com/?p=4312 etc..

I need to attach my code at the footer coz i am loading and some other stuff.

MY plugin's code is:

<?php

function myfunction(){
echo get_permalink($post->ID);  
}
add_action('wp_footer', 'myfunction');  

?>

Upvotes: 0

Views: 35

Answers (1)

Pagerange
Pagerange

Reputation: 234

$post is not in the scope of your function. Use the_post() to bring it into scope. Change your code to this:

<?php

function myfunction(){
the_post();
echo get_permalink($post->ID);  
}
add_action('wp_footer', 'myfunction');  

?>

Upvotes: 1

Related Questions