get_query_var()
. Например, вы можете использовать эту функцию в фильтре the_title
if ( ! function_exists( 'the_title_callback' ) ) {
/**
* Function for 'the_title' filter-hook.
*
* @param string $post_title The post title.
* @param int $post_id The post ID.
*
* @return string
*/
function the_title_callback( $post_title, $post_id ) {
$city = get_query_var( 'location_location1', false );
if ( $city && get_converter_cities( $city ) ) {
$post_title = $post_title . ' ' . get_converter_cities( $city );
}
return $post_title;
}
}
add_filter( 'the_title', 'the_title_callback', 10, 2 );
if ( ! function_exists( 'get_converter_cities' ) ) {
/**
* Return string or array with city values.
*
* @since 1.0.0
*
* @param string $control Key to get one value. Optional. Default null.
*
* @return string|array|false
*/
function get_converter_cities( $control = null ) {
// Sanitize string (just to be safe).
if ( ! is_null( $control ) ) {
$control = sanitize_title( $control );
}
// Main converter array.
$converter = array(
'abakan' => __( 'Abakan', 'domain' ),
'moscow' => __( 'Moscow', 'domain' ),
'saratov' => __( 'Saratov', 'domain' ),
);
$converter = apply_filters( 'get_converter_cities', $converter );
// Return controls.
if ( is_null( $control ) ) {
return $converter;
} elseif ( ! isset( $converter[ $control ] ) || empty( $converter[ $control ] ) ) {
return false;
} else {
return $converter[ $control ];
}
}
}
if ( ! function_exists( 'template_redirect_callback' ) ) {
/**
* Function for 'template_redirect` action-hook.
*
* @return void
*
* @since 1.0.0
*/
function template_redirect_callback() {
global $wp;
if ( str_contains( $wp->request, 'zapchasty/' ) ) {
$new_url = str_replace( 'zapchasty/', '/spareparts/', $wp->request );
wp_safe_redirect( home_url( trailingslashit( $new_url ) ), 301 );
}
}
}
add_action( 'template_redirect', 'template_redirect_callback' );
У нас есть сайт и мы хотим изменить подвал сайта
хотя все настройки Yoast SEO выполнены правильно
if ( ! function_exists( 'get_chatgpt_responce' ) ) {
/**
* Returns query result or error
*
* @param string $question Text API question.
* @param string $promt Text API promt (for chat).
* @param string $model API model.
* @param string $api_key API key.
*
* @return void
*/
function get_chatgpt_responce( $question = null, $promt = null, $model = 'gpt-3.5-turbo', $api_key = 'sk-le000000000000000000000000000000000000' ) {
if ( is_null( $question ) ) {
return null;
}
$type = 'text';
if ( $model === 'davinci-codex' ) {
$type = 'codex';
}
if ( in_array( $model, array( 'gpt-4', 'gpt-4-0314', 'gpt-4-32k', 'gpt-4-32k-0314', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0301' ), true ) ) {
$type = 'chat';
}
$headers = "Content-Type: application/json\r\n" . "Authorization: Bearer " . $api_key . "\r\n";
$params = array(
'model' => $model,
'temperature' => 0.7,
'top_p' => 1,
);
if ( $type === 'chat' ) {
$url = 'https://api.openai.com/v1/chat/completions';
$params['n'] = 1;
if ( ! is_null( $promt ) ) {
$params['messages'][] = array(
'role' => 'system',
'content' => $promt,
);
}
$params['messages'][] = array(
'role' => 'user',
'content' => $question,
);
} elseif( $type === 'codex' ) {
$url = 'https://api.openai.com/v1/engines/davinci-codex/completions';
$params['prompt'] = $question;
$params['max_tokens'] = 4096 - iconv_strlen( $question );
} else {
$url = 'https://api.openai.com/v1/completions';
$params['prompt'] = $question;
$params['max_tokens'] = 4096 - iconv_strlen( $question );
}
$args = array(
'method' => 'POST',
'timeout' => 240,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => $headers,
'body' => json_encode( $params ),
'sslverify' => true,
);
$response = wp_remote_request( $url, $args );
if ( is_wp_error( $response ) ) {
$notification = $response->get_error_message();
} elseif ( in_array( wp_remote_retrieve_response_code( $response ), array( 400, 401, 403, 404 ), true ) ) {
$body = json_decode( wp_remote_retrieve_body( $response ), true );
$notification = $body['error']['message'];
} elseif ( wp_remote_retrieve_response_code( $response ) === 200 ) {
$body = json_decode( wp_remote_retrieve_body( $response ), true );
$notification = 'Расход GPT токенов: ' . $body['usage']['total_tokens'] . '. Причина остановки: ' . $body['choices'][0]['finish_reason'];
if ( $type === 'chat' ) {
return $body['choices'][0]['message']['content'];
} else {
return $body['choices'][0]['text'];
}
}
if ( function_exists( 'telegram_notification' ) ) {
telegram_notification( $notification );
}
return false;
}
}
$query = 'Write a list frequently asked questions about the get_the_title() WordPress function.';
$chatgpt = get_chatgpt_responce( $query );
var_dump( $chatgpt );
add_filter( 'woocommerce_get_price_suffix', 'add_some_text_after_price', 99, 1 );
function add_some_text_after_price ( $value ) {
$value = get_post_meta( get_the_ID(), '_edinica', true );
if ( empty( $value ) ) {
return;
}
return '<span>/ <span>' . esc_html( $value ) . '</span></span>';
};
<?php
$args = array(
'category' => 4,
'orderby' => 'date',
'posts_per_page' => 4,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post(); ?>
<div class="col-md-3 col-sm-3 col-xs-12 off-pd line-item">
<div class="prod-card">
<?php $tags = get_the_tags(); ?>
<?php if ( $tags ) { ?>
<ul class="tag-list">
<?php foreach ( $tags as $key => $tag ) { ?>
<li class="tag-list__item">
<a href="<?php echo get_tag_link( $tag->term_id ); ?>" class="product-tag"></a>
</li>
<?php } ?>
</ul>
<?php } ?>
<img src="<?php the_post_thumbnail_url( 'medium' ); ?>" class="product-img img-responsive" ></a>
<div class="product-discr">
<p class="product-h"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></p>
<?php if ( get_field( 'short_diskr_post' ) ): ?>
<p class="product-short"><?php the_field( 'short_diskr_post' ); ?></p>
<?php endif; ?>
</div>
</div>
</div>
<?php
}
}
wp_reset_postdata();
?>
body_class()
и post_class()
. По аналогии вы можете создать свою функцию header_class()
с нужными вам условиями, пример:if ( ! function_exists( 'get_header_class' ) ) {
/**
* Get classes for header container.
*
* @param string $class Additional header classes.
*
* @return array
*/
function get_header_class( $class = '' ) {
// Add elements to array.
$classes = array();
$classes[] = 'header';
if ( has_custom_header() ) {
$classes[] = 'header_background-image';
}
if ( is_admin_bar_showing() ) {
$classes[] = 'is_wpadminbar';
}
if ( is_category( 'example' ) ) {
$classes[] = 'header_example';
}
// 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_header_class', $classes );
$classes = array_unique( (array) $classes );
return $classes;
}
}
if ( ! function_exists( 'header_class' ) ) {
/**
* Display classes for header container.
*
* @param string $class Additional header classes.
* @param bool $echo Echo or return header classes.
*
* @return string|void
*/
function header_class( $class = '', $echo = true ) {
$classes = get_header_class( $class );
if ( $echo ) {
echo 'class="' . esc_attr( implode( ' ', $classes ) ) . '"';
} else {
return 'class="' . esc_attr( implode( ' ', $classes ) ) . '"';
}
}
}
<header id="header" <?php header_class(); ?> aria-label="<?php _ex( 'Site header', 'aria-label', 'themename' ); ?>">
<!-- ... -->
</header>
function get_yoast_brand() {
$string = '';
if ( is_single() ) {
$string = get_post_meta( get_the_ID(), '_brand', true ) ?? __( 'Default Brand', 'textdomain' );
}
return $string;
}
// Define the action for register yoast_variable replacments.
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%Brand%%', 'get_yoast_brand', 'advanced', __( 'Description of this field', 'textdomain' ) );
}
// Add action.
add_action( 'wpseo_register_extra_replacements', 'register_custom_yoast_variables' );
/* Keyword value */
cursor: auto;
cursor: pointer;
/* … */
cursor: zoom-out;
/* URL with mandatory keyword fallback */
cursor: url(hand.cur), pointer;
/* URL and coordinates, with mandatory keyword fallback */
cursor: url(cursor_1.png) 4 12, auto;
cursor: url(cursor_2.png) 2 2, pointer;
/* URLs and fallback URLs (some with coordinates), with mandatory keyword fallback */
cursor: url(cursor_1.svg) 4 5, url(cursor_2.svg), /* … ,*/ url(cursor_n.cur) 5 5,
progress;
<ul>
нельзя вкладывать ничего, кроме элементов <li>
, но если очень хочется, то вам нужно создать расширенный экземпляр класса Walkerwp_get_nav_menu_items()
и сделать вывод в свою верстку add_shortcode( 'wp_city', 'wp_city' );
if ( ! function_exists( 'wp_city' ) ) {
/**
* Add shortcode with city [wp_city city=""]
*
* @param array $atts shortcode attributes.
*
* @return string
*/
function wp_city( $atts ) {
// Define a white list of attributes.
$atts = shortcode_atts( array(
'city' => __( 'Moscow', 'default' ),
), $atts );
$output = '<span class="current-city">' . esc_html( $atts['city'] ) . '</span>';
return apply_filters( 'wp_city', $output );
}
}
public => false
функции register_post_type()
. У этой записи не будет ссылки во фронте, но будут все возможности редактирования в админке. Запросить записи для вывода во фронт можно произвольным запросом wp_query()