Шорткод вставляет абзацы до и после выполнения шорткода


Когда мой шорткод выполняется, он вставляет <p></p> до и после шорткода.

Мой шорткод - это единственное, что есть в текстовом редакторе страницы. До или после моего шорткода нет новой строки.

Вот мои функции шорткода:

//* Shortcode for child pages
function list_sub_pages( $atts ) {

    extract( shortcode_atts(array('page' => 'home', 'display' => 'excerpt', 'show' => '3', 'speed' => '10'),$atts));

        $page_id = get_page_by_path($page);

    switch ( $display ) {
        case 'excerpt':
            $content = display_page_excerpt($page_id, (int) $speed);
            break;
        case 'kids':
            $content = display_child_pages($page_id, (int) $show, (int) $speed);
            break;
        case 'blog':
            $content = display_blog_posts((int) $show, (int) $speed);
            break;
        default:
        break;
    }


    return $content;
}
add_shortcode('group', 'list_sub_pages');

function display_page_excerpt( $page_id = 1, $speed = 10 ){
    $page_data = get_page($page_id->ID);

    $output = '<section id="'.$page_id->post_name.'">';
    $output .= '<div class="'.$page_id->post_name.'-bkgd" data-type="background" data-speed="'.$speed.'"></div><div class="wrap">';
    $output .= '<blockquote class="'.$page_id->post_name.'">'.$page_data->post_excerpt.'</blockquote>';
    $output .= '</div></section>';

        return $output;
}

function display_child_pages( $page_id = 1, $show = 3, $speed = 10 ){
    global $post;

    //query subpages
    $args = array(
        'post_parent' => $page_id->ID,
        'showposts' => $show,
        'post_type' => 'page',
        'orderby' => 'menu_order',
        'order' => 'ASC'
    );
    $subpages = new WP_query($args);

    // create output
    if ($subpages->have_posts()) :
        $output = '<section id="'.$page_id->post_name.'">';
        $output .= '<div class="'.$page_id->post_name.'-bkgd" data-type="background" data-speed="'.$speed.'"></div><div class="wrap">';
        $output .= '<h2 class="'.$page_id->post_name.'-title home-titles"><i class="icon-home-title-'.$page_id->post_name.'"></i>';
        $output .= get_the_title($page_id->ID);
        $output .= '</h2><ul class="'.$page_id->post_name.'">';
        while ($subpages->have_posts()) : $subpages->the_post();
            $output .= '<li><a href="'.get_permalink().'" class="'.$page_id->post_name.'-link"><div class="'.$page_id->post_name.'-info"><div class="'.$page_id->post_name.'-img">'.get_the_post_thumbnail($page->ID,'icons').'</div><h2>'.get_the_title().'</h2>
                        <p class="'.$page_id->post_name.'-excerpt">'.get_the_excerpt().'</p>
                        </div></a></li>';
        endwhile;
        $output .= '</ul>';
        $output .= '<div style="clear: both;"></div></div></section>';
    endif;

    // reset the query
    wp_reset_postdata();

    // return something
    return $output;
}

function display_blog_posts( $show = 3, $speed = 10 ){

    $output = '<section id="blog" data-type="background" data-speed="'.$speed.'">';
    $output .= '<div class="blog-bkgd" data-type="background" data-speed="'.$speed.'"></div><div class="wrap">';
    $output .= '<h2 class="blog-title home-titles"><i class="icon-home-title-blog"></i>Recent News</h2><ul class="recent-posts">';

    $args = array(
        'numberposts' => $show,
        'order' => 'post_date',
        'order' => 'DESC',
        'post_status' => 'publish'
    );  
    $posts = wp_get_recent_posts($args);
    foreach( $posts as $post ){
        $post_id = $post["ID"];

        $output .= '<li><a href="' . get_permalink($post_id) . '" title="'.esc_attr($post["post_title"]).'" ><h2>'.$post["post_title"].'</h2><p class="blog-excerpt">'.$post["post_excerpt"].'</p></a></li> ';
    }

    $output .= '</ul>';
    $output .= '</div></section>';

    // reset the query
    wp_reset_postdata();

    return $output;
}

Вот как выглядит HTML-разметка в моем браузере.

enter image description here

Итак, мне нужно выяснить, откуда берутся эти мошеннические абзацы. Любое понимание было бы значительно оцененный. Спасибо!

Author: NW Tech, 2013-10-30

1 answers

Я думаю, что это результат wpautop фильтра, работающего на the_content. Вы можете удалить этот фильтр из содержимого:

remove_filter('the_content', 'wpautop');
// OR if the above line does not work:
add_filter('the_content', 'remove_autop', 1);
function remove_autop($content) {
    remove_filter(current_filter(), 'wpautop');
    return $content;
}

Или вы можете использовать фильтр shortcode_unautop, но это будет работать только в том случае, если ваш шорткод не содержит другого содержимого в текстовом редакторе:

add_filter('the_content', 'shortcode_unautop');
 1
Author: Ahmad M, 2013-10-31 10:49:24