Force full-width post on post options for specific tag

Hey. I have a question. I’m sure it’s a child theme functions.php thing.

I want to automatically force posts with a certain tag to be fullwidth in Ethos yet leave others (without that tag) with the default (sidebar) style

How to make this happen?

(this would ideally allow me and other Authors in my multisite to tag a bunch of posts simultaneously from the post listing window which would then make them all fullwidth while e l saving non-tagged posts alone)

Hi Peter,

Thank you for reaching out to us. There is built-in feature to enable the full-width layout of posts. To do that edit the posts you want to make fullwidth in WordPress editor and turn on the Fullwidth Post Layout option under Posts Settings (see screenshot)

Hope this helps!

I get that. Im already doing that. I was wondering about how to set that for a whole series of posts with a specific tag

Hello Peter,

The setting is for individual posts. Regretfully there aren’t any option for all the posts using the same tag. It will only be possible with custom PHP code. Perhaps this code might help by adding this in your child theme’s functions.php file:

// 
// Make some posts to display as Fullwidth
// =============================================================================
function no_sidebars_on_post($contents) {
  if ( has_tag('some tag') ) {
    $contents = 'fullwidth';
  }
  
  return $contents;
}
add_filter('x_option_x_layout_content', 'no_sidebars_on_post', 5);
// =============================================================================

The some tag in the code above needs to be changed to the correct tag name.

Reference Thread:

STRANGELY enough, it made the post full-width, yet put the sidebar at the bottom of the page. How to remove the sidebar completely?

Hey Peter,

Please remove the given php code and replace this one instead:

if ( ! function_exists( 'x_get_content_layout' ) ) :
  function x_get_content_layout() {

    $content_layout = x_get_option( 'x_layout_content' );

    if ( $content_layout != 'full-width' ) {
      if ( is_home() ) {
        $opt    = x_get_option( 'x_blog_layout' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_singular( 'post' ) ) {

        //
        // =============================================================================
        if ( has_tag('some tag') ) {

          $layout = 'full-width';

        } else {
          $meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
          $layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
        }
        // =============================================================================

      } elseif ( x_is_portfolio_item() ) {
        $layout = 'full-width';
      } elseif ( x_is_portfolio() ) {
        $meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
        $layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
      } elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
        $layout = 'content-sidebar';
      } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
        $layout = 'sidebar-content';
      } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
        $layout = 'full-width';
      } elseif ( is_archive() ) {
        if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
          $opt    = x_get_option( 'x_woocommerce_shop_layout_content' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        } else {
          $opt    = x_get_option( 'x_archive_layout' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        }
      } elseif ( x_is_product() ) {
        $layout = 'full-width';
      } elseif ( x_is_bbpress() ) {
        $opt    = x_get_option( 'x_bbpress_layout_content' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( x_is_buddypress() ) {
        $opt    = x_get_option( 'x_buddypress_layout_content' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_404() ) {
        $layout = 'full-width';
      } else {
        $layout = $content_layout;
      }
    } else {
      $layout = $content_layout;
    }

    return $layout;

  }
endif;

Of course, has_tag('some tag') needs to be replaced with the correct tag.

That worked. As always, most thankful.

You’re most welcome, Peter.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.