Wordpress 在短代码中显示子页面的父页面 URL 不起作用
Wordpress Display parent page URL for child page in a shortcode not working
WordPress 在短代码中为子页面显示父页面 URL
问题是我无法用简单的简码显示
function page_url_shortcode(){
global $post;
if ( $post->post_parent ) {
echo get_permalink( $post->post_parent );
}
}
add_shortcode('title_url','page_url_shortcode');
短代码[title_url]
简码应该是 return 的东西,而不是回显输出。根据文档 (https://developer.wordpress.org/reference/functions/add_shortcode/):
Note that the function called by the shortcode should never produce an
output of any kind. Shortcode functions should return the text that is
to be used to replace the shortcode.
将您的永久链接调用更改为:
return get_the_permalink($post->post_parent);
WordPress 在短代码中为子页面显示父页面 URL 问题是我无法用简单的简码显示
function page_url_shortcode(){
global $post;
if ( $post->post_parent ) {
echo get_permalink( $post->post_parent );
}
}
add_shortcode('title_url','page_url_shortcode');
短代码[title_url]
简码应该是 return 的东西,而不是回显输出。根据文档 (https://developer.wordpress.org/reference/functions/add_shortcode/):
Note that the function called by the shortcode should never produce an output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode.
将您的永久链接调用更改为:
return get_the_permalink($post->post_parent);