Здравствуйте, я пытаюсь преобразовать свой файл grid.css в шорткоды wordpress, но у меня возникла проблема.

Что хочу увидеть:

<div class="row>
    <div class="columns one">Content</div>
    <div class="columns three">Content</div>
</div>

Что я получаю:

[column_one]Awesome[/column_one] [column_three]Stuff[/column_three]

Мой код:

<?php while ( have_posts() ) : the_post();
$content = get_the_content();
echo do_shortcode($content);
endwhile; // end of the loop. ?>

Я пробую это на простом шаблоне страницы.

Как мне заставить его работать правильно?

Спасибо.

1
user1993382 29 Янв 2013 в 03:10

1 ответ

Лучший ответ

Вам не нужно добавлять do_shortcode в свой цикл. Лучше было бы добавить его в файл functions.php вот так:

function column_one( $atts, $content = null ) {
    return '<div class="columns one">'.do_shortcode($content).'</div>';
}

add_shortcode('column_one', 'column_one'); 
1
user2019515 29 Янв 2013 в 04:03