$current_date = date( 'd-m-Y H:i:s' );
$publish_date = get_the_date( 'd-m-Y H:i:s' );
$modified_date = get_the_modified_date( 'd-m-Y H:i:s' );
if ( strtotime( $publish_date . ' + 1 day' ) > strtotime( $current_date ) ) {
echo '<div class="badge">' . __( 'New', 'themename' ) . '</div>';
}
get_the_modified_date()
echo '<div class="badge hidden" data-publish-date="' . esc_attr( get_the_date( 'd M Y H:i:s O' ) ) . '">' . __( 'New', 'themename' ) . '</div>';
/* Direktiva robots */
function wporg_wp_robots_add_follow( $robots ) {
unset( $robots['max-image-preview'] );
if ( ! isset( $robots['noindex'] ) ) {
$robots['index'] = true;
$robots['follow'] = true;
}
$robots['noodp'] = true;
$robots['noydir'] = true;
return $robots;
}
add_filter( 'wp_robots', 'wporg_wp_robots_add_follow' );
wp_enqueue_scripts
функциями wp_enqueue_style()
и wp_enqueue_script()
function common_scripts() {
wp_enqueue_style( 'common-styles', get_theme_file_uri( 'assets/css/common.min.css' ), array(), filemtime( get_theme_file_path( '/assets/css/common.min.css' ) ) );
wp_enqueue_script( 'common-scripts', get_theme_file_uri( 'assets/js/common.min.js' ), array( 'jquery' ), filemtime( get_theme_file_path( '/assets/js/common.min.js' ) ), true );
}
add_action( 'wp_enqueue_scripts', 'common_scripts' );
wp_add_inline_style()
function common_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri(), array(), filemtime( get_theme_file_path( '/style.css' ) ) );
$css = '
.breadcrumbs_yoast ul, .breadcrumbs_yoast ol {
padding: 0;
margin: 0;
list-style-type: none;
}
.breadcrumbs_yoast ul * , .breadcrumbs_yoast ol * {
vertical-align: top;
}
.breadcrumbs_yoast ul li, .breadcrumbs_yoast ol li {
display: inline-block;
margin-right: .25rem;
}
.breadcrumbs_yoast ul li:not(:first-child), .breadcrumbs_yoast ol li:not(:first-child) {
display: inline-block;
margin-left: .25rem;
}';
wp_add_inline_style( 'common-styles', $css );
}
add_action( 'wp_enqueue_scripts', 'common_scripts' );
body_class()
и post_class()
if ( ! function_exists( 'get_wpgen_header_classes' ) ) {
/**
* Get classes for header container.
*
* @param string $class Additional header classes.
*
* @return array
*/
function get_wpgen_header_classes( $class = '' ) {
// Add elements to array.
$classes = array();
$classes[] = 'header';
if ( has_custom_header() ) {
$classes[] = 'header--background-image';
}
if ( is_front_page() || is_home() ) {
$classes[] = 'header-bg';
} else {
$classes[] = 'custom-class';
}
// Check the function has accepted any classes.
if ( isset( $class ) && ! empty( $class ) ) {
if ( is_array( $class ) ) {
$classes = array_merge( $classes, $class );
} elseif ( is_string( $class ) ) {
$classes = array_merge( $classes, explode( ' ', $class ) );
}
}
$classes = apply_filters( 'get_wpgen_header_classes', $classes );
// Usage:
/*add_filter( 'get_wpgen_header_classes', 'my_header_classes' );
if ( ! function_exists( 'my_header_classes' ) ) {
function my_header_classes( $classes ) {
$classes[] = 'my-class';
return array_unique( $classes );
}
}*/
return array_unique( (array) $classes );
}
}
if ( ! function_exists( 'wpgen_header_classes' ) ) {
/**
* Display classes for header container.
*
* @param string $class Additional header classes.
* @param bool $echo Echo or return header classes.
*
* @return string
*/
function wpgen_header_classes( $class = '', $echo = true ) {
$classes = get_wpgen_header_classes( $class );
if ( $echo ) {
echo 'class="' . esc_attr( implode( ' ', $classes ) ) . '"';
} else {
return 'class="' . esc_attr( implode( ' ', $classes ) ) . '"';
}
}
}
<header id="header" <?php wpgen_header_classes(); ?>>
<header id="header" <?php wpgen_header_classes( 'new-class' ); ?>>
$separator = '|';
// Title prefixes.
if ( is_post_type_archive() ) {
$title[] = _x( 'Archives:', 'post type archive title prefix', 'wpgen' );
} elseif ( is_category() ) {
$title[] = _x( 'Category:', 'category archive title prefix', 'wpgen' );
} elseif ( is_tag() ) {
$title[] = _x( 'Tag:', 'tag archive title prefix', 'wpgen' );
} elseif ( is_author() ) {
$title[] = _x( 'Author:', 'author archive title prefix', 'wpgen' );
} elseif ( is_date() ) {
if ( is_year() ) {
$title[] = _x( 'Year:', 'date archive title prefix', 'wpgen' );
} elseif ( is_month() ) {
$title[] = _x( 'Month:', 'date archive title prefix', 'wpgen' );
} elseif ( is_day() ) {
$title[] = _x( 'Day:', 'date archive title prefix', 'wpgen' );
}
} elseif ( is_tax( 'post_format' ) ) {
if ( is_tax( 'post_format', 'post-format-aside' ) ) {
$title[] = _x( 'Asides', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
$title[] = _x( 'Galleries', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
$title[] = _x( 'Images', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
$title[] = _x( 'Videos', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
$title[] = _x( 'Quotes', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
$title[] = _x( 'Links', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
$title[] = _x( 'Statuses', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
$title[] = _x( 'Audio', 'post format archive title', 'wpgen' );
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
$title[] = _x( 'Chats', 'post format archive title', 'wpgen' );
}
}
// Main title.
if ( is_single() || is_page() ) {
$title[] = get_the_title();
} elseif ( is_404() ) {
$title[] = __( 'Page not found', 'wpgen' );
} elseif ( is_search() ) {
$title[] = sprintf( __( 'Search Results for “%s”', 'wpgen' ), get_search_query( false ) );
} elseif ( is_post_type_archive() ) {
$title[] = get_queried_object()->label;
} elseif ( is_author() ) {
$title[] = get_queried_object()->display_name ?? '';
} elseif ( is_date() ) {
if ( is_year() ) {
$title[] = get_the_date( 'Y' );
} elseif ( is_month() ) {
$title[] = get_the_date( 'F Y' );
} elseif ( is_day() ) {
$title[] = get_the_date( 'F j, Y' );
}
} elseif ( is_archive() ) {
$title[] = get_queried_object()->name;
}
// Add site info in the title.
if ( ! isset( $title ) ) {
$title[] = get_bloginfo( 'name' );
$title[] = $separator;
$title[] = get_bloginfo( 'description' );
} else {
if ( is_paged() ) {
$title[] = $separator;
$title[] = __( 'Page', 'wpgen' ) . ' ' . $paged;
}
$title[] = $separator;
$title[] = get_bloginfo( 'name' );
}
$title = implode( ' ', $title );
wp_get_nav_menu_items()
и вывести свою разметку// Получаем элементы меню по ID.
$nav_menu_items = wp_get_nav_menu_items( $menu_id );
// Или получаем элементы меню по location.
$menu_location = 'primary';
$locations = get_nav_menu_locations();
if ( isset( $locations[ $menu_location ] ) ) {
$nav_menu_items = wp_get_nav_menu_items( $locations[ $menu_location ] );
}
__()
, _e()
, esc_html__()
, esc_html_e()
, _x()
и _ex()
_x( 'Read', 'past participle: books I have read', 'text_domain' );
load_theme_textdomain()
register_post_type()
и register_taxonomy()
get_template_part( 'templates/archive/post', get_post_type() );
pre_get_posts
wp_get_nav_menu_items()
по переданному ID или location// Получаем элементы меню по ID.
$nav_menu_items = wp_get_nav_menu_items( $menu_id );
// Получаем элементы меню по location.
$menu_location = 'primary';
$locations = get_nav_menu_locations();
if ( isset( $locations[ $menu_location ] ) ) {
$nav_menu_items = wp_get_nav_menu_items( $locations[ $menu_location ] );
}
pre_get_posts
. Используйте проверки is_date()
, is_year()
, is_month()
и is_day()
template_redirect
с теми же проверками