参考号:how to get page id of a page using page slug
我检查了上述答案,但当我将任何代码粘贴到子主题的函数php文件中时,它没有改变任何内容。以下是我使用的代码:
<?php
// For this theme only - not the standard way of enqueing styles as per here:
// https://wordpress.org/support/topic/adding-child-theme?replies=3
function smallblog_child_scripts() {
wp_enqueue_style( \'smallblog-child\', get_stylesheet_directory_uri() . \'/style.css\' );
}
add_action( \'wp_enqueue_scripts\', \'smallblog_child_scripts\', 20 );
function get_id_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
}
?>
页面id仍仅显示。例如,不显示
class="page page-id-53 page-template-default
我希望它显示:class="page contact page-template-default //indicating that\'s the contact page
谢谢你的帮助!