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 eg 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');
?>
$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');
?>
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.