add amp
This commit is contained in:
7
amp.css
Normal file
7
amp.css
Normal file
@@ -0,0 +1,7 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
}
|
||||
@@ -988,3 +988,17 @@ function adddr_hash(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Пример замены изображений на AMP-изображения в контенте поста
|
||||
function convert_images_to_amp($content) {
|
||||
if (function_exists('is_amp_endpoint') && is_amp_endpoint()) {
|
||||
$content = preg_replace(
|
||||
'/<img(.*?)src="(.*?)"(.*?)>/i',
|
||||
'<amp-img$1src="$2"$3 layout="responsive" width="600" height="400"></amp-img>',
|
||||
$content
|
||||
);
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
add_filter('the_content', 'convert_images_to_amp');
|
||||
|
||||
|
||||
39
single-amp.php
Normal file
39
single-amp.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// Включение стилей AMP
|
||||
function theme_amp_styles() {
|
||||
wp_enqueue_style('theme-amp-style', get_template_directory_uri() . '/amp.css');
|
||||
}
|
||||
add_action('amp_post_template_css', 'theme_amp_styles');
|
||||
|
||||
// Начало AMP страницы
|
||||
?>
|
||||
<!doctype html>
|
||||
<html amp>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<script async src="https://cdn.ampproject.org/v0.js"></script>
|
||||
<title><?php the_title(); ?></title>
|
||||
<link rel="canonical" href="<?php echo esc_url(get_permalink()); ?>">
|
||||
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
|
||||
<style amp-custom>
|
||||
<?php
|
||||
// Включение стилей из amp.css
|
||||
readfile(get_template_directory() . '/amp.css');
|
||||
?>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<article>
|
||||
<header>
|
||||
<h1><?php the_title(); ?></h1>
|
||||
</header>
|
||||
<div>
|
||||
<?php
|
||||
while (have_posts()) : the_post();
|
||||
the_content();
|
||||
endwhile;
|
||||
?>
|
||||
</div>
|
||||
</article>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user