Пытается использовать фильтр для сообщений. Но как я могу заставить IF работать внутри функции.
<?php function my_the_content_filter($content) { } add_filter( 'the_content', 'my_the_content_filter' ); ?>
Поэтому мне нужно добавить это внутри него.
<?php if (get_post_meta($post->ID, "heading_image", true)) : ?> <img src="<?php $image_id = get_post_meta($post->ID, "heading_image", true); $post_image_data = wp_get_attachment_image_src( $image_id, $size='full' ); echo $post_image_data[0]; ?>" style="max-width:1000px;" /> <?php endif; ?>
Я не могу отформатировать его правильно.
Это должно быть так –
<?php function my_the_content_filter( $content ) { if( get_post_meta( get_the_ID(), "heading_image", true) ) { $image_id = get_post_meta( get_the_ID(), "heading_image", true); $post_image_data = wp_get_attachment_image_src( $image_id, 'full' ); ?> // checks if you have got the source if( isset($post_image_data[0]) ) { // if image is show before the content $content = '<img src="'. $post_image_data[0] .'" style="max-width:1000px;" />' . $content; } } return $content; } add_filter( 'the_content', 'my_the_content_filter' ); ?>