pre_get_document_title
, который позволяет переопределить заголовок, а не полностью убить функциюif ( ! function_exists( 'pre_get_document_title_callback' ) ) {
/**
* Function for 'pre_get_document_title' filter-hook.
*
* @param string $title The document title.
*
* @return string
*/
function pre_get_document_title_callback( $title ) {
if ( is_home() || is_front_page() ) {
$title = get_field( 'home_page_title' );
}
if ( is_single() ) {
$title = get_field( 'home_page_title' );
}
if ( is_category() ) {
$title = get_field( 'home_page_title' );
}
if ( is_page( 16 ) ) {
$title = get_field( 'download_title' );
}
if ( is_page( 18 ) ) {
$title = get_field( 'faq_page_title' );
}
return $title;
}
}
add_filter( 'pre_get_document_title', 'pre_get_document_title_callback' );
jQuery( document ).ready( function ( $ ) {
function mediaUploader( buttonClass ) {
// Trigger the Media Uploader dialog.
$( document ).on( 'click', buttonClass, function( e ) {
var mediaUploader;
form = $( buttonClass ).closest( 'form' )
// If the uploader object has already been created, reopen the dialog.
if ( mediaUploader ) {
mediaUploader.open();
return;
}
// Extend the wp.media object.
var mediaUploader = wp.media.frames.file_frame = wp.media( {
title: 'Select Image',
button: {
text: 'Select Image'
},
multiple: false,
library: {
type: 'image'
},
} );
// When a file is selected, grab the URL and set it as the text field's value.
mediaUploader.on( 'select', function () {
var attachment = mediaUploader.state().get( 'selection' ).first().toJSON();
form.find( '.image-upload' ).val( attachment.url );
form.find( '.media-image-container' ).empty();
form.find( '.media-image-container' ).append( '<img src="' + attachment.url + '" class="media-image" alt="Image Preview" style="max-width:100%;margin-bottom:10px" />' );
$( '.media-modal:visible' ).find( '.media-modal-close' ).trigger( 'click' );
} );
// Open the uploader dialog.
mediaUploader.open();
} );
}
// Initialize media uploader.
mediaUploader( '.button-add-adv-media' );
} );
<?php case 'image':
?>
<div class="media-widget-control">
<p>
<label for="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>"><?php echo wp_kses_post( $setting['label'] ); ?></label><?php // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
<input class="widefat image-upload <?php echo esc_attr( $class ); ?>" id="<?php echo esc_attr( $this->get_field_id( $key ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( $key ) ); ?>" type="hidden" value="<?php echo esc_attr( $value ); ?>" />
</p>
<div class="media-widget-preview">
<div class="media-image-container">
<?php if ( ! empty( $value ) ) : ?>
<img src="<?php echo esc_url( $value ) ; ?>" alt="Image Preview" style="max-width:100%;margin-bottom:10px" />
<?php endif; ?>
</div>
<div class="attachment-media-view">
<button type="button" class="select-media button-add-media button-add-adv-media not-selected"><?php esc_html_e( 'Add image', 'aesthetix' ); ?></button>
</div>
</div>
<?php if ( isset( $setting['desc'] ) ) : ?>
<small><?php echo esc_html( $setting['desc'] ); ?></small>
<?php endif; ?>
</div>
<?php
break;
$mask = array();
$mask['type'] = 'FeatureCollection';
foreach ( $resorts as $key => $resort ) {
$geo_point = get_post_meta( $resort->ID, '_geo_location', true );
$geo_point = explode( ',', $geo_point );
// Собираем php массив для карты, который энкодим в json формат
$mask['features'][] = array(
'type' => 'Feature',
'id' => $key,
'geometry' => array (
'type' => 'Point',
'coordinates' => [(float) trim($geo_point[0]), (float) trim($geo_point[1])],
),
'properties' => array (
'balloonContentBody' => '<strong class="balloon-title"><a class="link" href="' . esc_url( get_the_permalink( $resort->ID ) ) . '" target="_blank">' . $resort->post_title . '</a></strong>',
'clusterCaption' => '<strong>' . $resort->post_title . '</strong>',
'hintContent' => '<strong>' . $resort->post_title . '</strong>'
)
);
}
json_encode()
и wp_add_inline_script()
вставляю все во фронт$frontend_scripts = "<script type='text/javascript'>
jQuery(function($){
ymaps.ready(init);
function init () {
var map = new ymaps.Map('ya-map', {
center: [55.76, 37.64],
zoom: 4,
controls: ['geolocationControl' ,'zoomControl'],
}, {
avoidFractionalZoom: false,
});
map.behaviors.disable(\"scrollZoom\");
var objectManager = new ymaps.ObjectManager({
clusterize: true,
gridSize: 32,
clusterDisableClickZoom: true
});
objectManager.objects.options.set( 'preset', 'islands#greenCircleDotIcon' );
objectManager.clusters.options.set( 'preset', 'islands#greenClusterIcons' );
map.geoObjects.add(objectManager);
var pointLabels = " . json_encode( $mask ) . ";
objectManager.add(pointLabels);
// эта костыльная хуйня центрирует карту и делает автозум, чтобы попали все точки
var geoObjects = ymaps.geoQuery(pointLabels)
.applyBoundsToMap(map, {
checkZoomRange: true
});
}
});
</script>";
wp_add_inline_script( 'main', minify_js( $frontend_scripts ) );
query_vars
if ( ! function_exists( 'get_converter_wp_cities' ) ) {
/**
* Return string or array with wp cities.
*
* @param string $control Key to get one value. Optional. Default null.
*
* @return string|array|false
*/
function get_converter_wp_cities( $control = null ) {
// Sanitize string (just to be safe).
if ( ! is_null( $control ) ) {
$control = get_title_slug( $control );
}
// Main converter array.
$converter = array(
'moscow' => 'Москва',
'saint-petersburg' => 'Санкт-Петербург',
'novosibirsk' => 'Новосибирск',
);
$converter = apply_filters( 'get_converter_wp_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( 'query_vars_wp_cities' ) ) {
/**
* Function for 'query_vars' filter-hook.
*
* @param string[] $public_query_vars The array of allowed query variable names.
*
* @return string[]
*/
function query_vars_wp_cities( $public_query_vars ){
$public_query_vars[] = 'city';
return $public_query_vars;
}
}
add_filter( 'query_vars', 'query_vars_wp_cities' );
add_query_arg()
echo '<ul class="city-list">';
foreach ( get_converter_wp_cities() as $key => $city ) {
$url = add_query_arg( array( 'city' => $key ), get_home_url( '/' ) );
echo '<li class="city-list-item"><a href="' . esc_url( $url ) . '" class="link">' . esc_html( $city ) . '</a></li>';
}
echo '</ul>';
get_query_var()
$city = get_query_var( 'city', false );
var_dump( $city );
register_post_type()
и register_taxonomy()
, а создать записи wp_insert_post()
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' => get_query_var( 'city', false ),
), $atts );
if ( $atts['city'] ) {
$output = '<span class="current-city">' . esc_html( get_converter_wp_cities( $atts['city'] ) ) . '</span>';
}
return apply_filters( 'wp_city', $output );
}
}
add_shortcode( 'wp_city', 'wp_city' );
function get_yoast_current_city() {
$city = get_query_var( 'city', false );
if ( $city ) {
$string = $city;
} else {
$string = '';
}
return $string;
}
// Define the action for register yoast_variable replacments.
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%CurrentCity%%', 'get_yoast_current_city', 'advanced', __( 'Some instead title text', 'wpgen' ) );
}
// Add action.
add_action( 'wpseo_register_extra_replacements', 'register_custom_yoast_variables' );
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>