WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post formats and structured post formats by default without add_theme_support (15 posts)

  1. Jason (Theme Blvd)
    Member
    Posted 1 year ago #

    I didn't want to post this in trac, because I feel like I'm missing something simple or I'm out of the loop on something.

    These all seem to not do anything within a theme:

    add_theme_support('post-formats');
    add_theme_support('structured-post-formats');
    
    remove_theme_support('post-formats');
    remove_theme_support('structured-post-formats');

    It seems that themes support post-formats/structured-post-formats by default, and there's no way to remove it? Does this mean all themes moving forward need to incorporate post formats? Or is this a temporary thing that just hasn't been completed in the current beta?

    In looking at WP 3.6-beta1 core and some of these functions, I see a few places where "structured-post-formats" appears but in places that seem to be incomplete within functions like add_theme_support() and current_theme_supports() -- So that's what got me thinking maybe this is just something that's not finished yet.

  2. Themes will not support post-formats by default. You still have to add support for them using add_theme_support()

    Your code sample above is missing the array of post formats to support. See example from twentythirteen:

    /*
      * This theme supports all available post formats.
      * See http://codex.wordpress.org/Post_Formats
      *
      * Structured post formats are formats where Twenty Thirteen handles the
      * output instead of the default core HTML output.
      */
     add_theme_support( 'structured-post-formats', array(
     	'link', 'video'
     ) );
     add_theme_support( 'post-formats', array(
      	'aside', 'audio', 'chat', 'gallery', 'image', 'quote', 'status'
    ) );

    Also to note is that these calls need to be in a function attached to the 'after_setup_theme hook.

  3. Jason (Theme Blvd)
    Member
    Posted 1 year ago #

    Hey Chris,

    Thanks for responding. You're totally right on the snippet I posted, however I believe I am still seeing the issue I was trying to point out.

    Here's how to reproduce the issue:

    With v3.6-beta1 and TwentyThirteen activated, open up TwentyThirteen's functions.php and comment out lines 76-81 where it adds theme support for post formats (where you copied from previously).

    add_theme_support( 'structured-post-formats', array(
    	'link', 'video'
    ) );
    add_theme_support( 'post-formats', array(
    	'aside', 'audio', 'chat', 'gallery', 'image', 'quote', 'status'
    ) );

    After doing this, I see that post formats are still available in the WordPress admin panel when editing posts.

    And if I activate any themes that I've created that do not support post formats, I also see post formats in the Edit Post page of the WP admin.

    Is this not the case for you?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    That would be the correct behaviour for 3.6 and marks a change of direction with Post Formats generally. Post Formats will now show up even when a theme doesn't explicitly support them. Themes that explicitly support 1 or more Post Formats will now be assumed to do "something special" display-wise.

    Does that make sense?

  5. Jason (Theme Blvd)
    Member
    Posted 1 year ago #

    I guess where I'm confused is with what actually add_theme_support is doing now with the post-formats/structured-post-formats in 3.6. Why put this in your theme at all if they are on by default? Something just seems off to me here. I must be missing something.

    When I comment out these add_theme_support uses in TwentyThirteen, I can't figure out what changes in terms of the the WP admin in editing posts or the frontend display of the posts. Everything seems to be the same whether support has been added by theme or not.

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    I guess where I'm confused is with what actually add_theme_support is doing now

    You're not the only one!

    theme support for a post format now functions as a flag that says that the theme handles the metadata so core should leave it alone

    http://core.trac.wordpress.org/ticket/19570

    And http://core.trac.wordpress.org/ticket/23347 deals with core fallbacks where themes don't declare support for a format. Have a look at the "Post Formats Default HTML Output". That may change but it gives you some idea of how core might be handling the different post format output compared to your own theme's post format templates files.

    As I understand it, if you use add_theme_support, your theme's handling of post formats will take precedence and core will handle anything that you didn't explicitly support. For the most part, if all you're doing is some fancy CSS based on the post-format classes (which, I think, is what 2013 is doing), you may not see much change but if you have very specialised post format template files, they'll be used as opposed to core's default output.

    That said, I've not has much time to play with this yet. I've got one theme of my own that does have a range of post format templates and I need to how/if they differ from the 3.6 core output.

  7. Jason (Theme Blvd)
    Member
    Posted 1 year ago #

    @esmi Thanks for taking the time to give me your take on this.

    I've digging through core a bit more and have noticed some things on this.

    1) When you add theme support for "post-formats", it gets registered globally, but in searching through 3.6 with my text editor, I don't see any places where this support is actually checked to do anything. (In WP 3.5 you can see it checked in many places)

    2) When you add theme support for "structured-post-formats" it seems that the only real purpose here is that the fallbacks of post_formats_compat() on those registered formats don't get applied with using the_content().

    ... All kind of interesting. Seems that if you're a theme author and you don't look into post formats with all of your themes, users are going to be quite confused when updating to 3.6. Things will kind of, sorta work OK with post_formats_compat, but not fully. I'm sure post_formats_compat will get improved a bit as we move a long, as well.

  8. kbanor
    Member
    Posted 1 year ago #

    HI EVERYONE SOS

    please kindly help out anyone, i already added the post format in functions.php but i need to edit the loop, i am a beginner. if anyone would kindly edit my code to allow for 'aside' and 'gallery' format, i will be glad.

    Loop-entry.php

    <?php
    global $data;
    $count=0;
    while (have_posts()) : the_post();
    $count++;
    ?>  
    
    <?php
    /*-----------------------------------------------------------------------------------*/
    // Posts Entry  - used in the blog page & archives
    /*-----------------------------------------------------------------------------------*/
    
    $margin = '';
    if($count == '2') $margin = 'remove-margin';
    ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class('loop-entry boxframe '. $margin .''); ?>>
    
    	<?php
    	//get image height value
    	if($data['entry_thumbnail_height']) {
    		$entry_thumbnail_height = $data['entry_thumbnail_height'];
    	} else {
    		$entry_thumbnail_height = '200';
    	}
    
    	//featured image
    	$thumb = get_post_thumbnail_id();
    	$img_url = wp_get_attachment_url($thumb,'full'); //get full URL to image
    	$featured_image = aq_resize( $img_url, 303, $entry_thumbnail_height, true ); //resize & crop the image
    
    	//show featured image if it exists
    	if($featured_image) {  ?>
        <div class="loop-entry-thumbnail">
            <a>" title="<?php the_title(); ?>">
                <img src="<?php echo $featured_image; ?>" alt="<?php echo the_title(); ?>" />
            </a>
        </div>
        <!-- /loop-entry-thumbnail -->
    	<?php } ?>
        <div class="loop-entry-details">
            <h2><a>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
           <?php echo wp_trim_words( get_the_content(), 25, '...' ); ?><a>" class="read-more"><?php _e('read more','fitnessmag'); ?> →</a>
    		<section class="loop-entry-meta">
    			<?php echo get_the_date(); ?> - <?php comments_popup_link( __( '0 Comments', 'fitnessmag' ), __( '1 Comment', 'fitnessmag' ), __( '% Comments', 'fitnessmag' ) ) ?>
    		</section><!--/post-meta -->
        </div>
        <!-- /loop-entry-details -->
    </article><!-- /entry -->
    
    <?php if($count == '2') { echo '<div class="clear"></div>'; $count=0; } endwhile; ?>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

  9. esmi
    Forum Moderator
    Posted 1 year ago #

    @kbanor: It is impolite to interrupt another poster's ongoing thread with a question of your own. It causes significant problems for the forum's volunteers and prevents us from being able to track issues by topic. Please post your own topic.

  10. kbanor
    Member
    Posted 1 year ago #

    My bad

  11. lemmonaid
    Member
    Posted 1 year ago #

    Hi guys,

    Back to the original question of this thread, I can't really see the improvement here for WordPress in terms of forcing all post formats to be enabled by default.

    I think many of us who take WordPress as CMS and build websites on top of it for clients will have a hard time to explain to customers what those (new) post formats mean? And what we can do if a customer asks us to remove the "Chat" post format (for example) as he/she doesn't use it?

    I think the registration of post formats that are supported in the theme in previous WP versions was just perfect. Could there be some improvements on this field for WP3.6 - just use the formats that are actually registered?

    Thanks,

    Oliver

  12. If you're building for a client, just use the code to turn them off.

    The logic goes, if we turn them off by default, people won't use them. if we turn them on, they might.

  13. lemmonaid
    Member
    Posted 1 year ago #

    Thanks for the answer. After reading the first post of this thread I've got the feeling that removing doesn't work either. So I'll try

    remove_theme_support('post-formats', array(...));
    remove_theme_support('structured-post-formats', array(...));
  14. Jason (Theme Blvd)
    Member
    Posted 1 year ago #

    Correct me if I'm wrong, @Ipstenu, but I think she was referring to the new filter added to remove the post formats UI.

    http://core.trac.wordpress.org/ticket/23929

    add_filter( 'show_post_format_ui', '__return_false' );

    This was added after 3.6-beta1, I believe. So, still very new. It appears someone also suggested the idea of actually being able to remove specific formats in that ticket, which no one really seemed to comment to. (So maybe a chance to get your voice in! :) )

    Also, from looking around, it appears all of this is definitely not set in stone. While it seems likely that post formats will essentially be on by default, there are still discussions about it. But right now, the Post Formats UI in general seems to be a real work in progress. So we kind of need to wait to see how things evolve still.

  15. Jason (Theme Blvd)
    Member
    Posted 1 year ago #

    I also wanted to point out on this after doing quite a bit of digging with the structured post formats, I have found that "adding theme support" for this isn't exactly what it seems and I think will cause confusion for many.

    When you do:

    add_theme_support('structured-post-formats', array(...));

    You're not saying that your theme supports the structured data, you're saying that you don't want that data automatically filtered onto the_content(), which is what WordPress's new posts_formats_compat is. In other words, adding support just means the fallback behavior isn't applied to the the_content().

    For example, say you had this in your template file for displaying an image format post:

    <div class="entry-media">
    	<?php the_post_format_image(); ?>
    </div>
    <div class="entry-content">
    	<?php the_content(); ?>
    </div>

    Initially, this will show the image inputted through the post format UI twice. You'll get it once above and once at the bottom of the content. However, if you were to add "structured-post-formats" support for the image format, now it would NOT show the image at the bottom of the_content().

    An alternate approach would be to do this:

    <div class="entry-media">
    	<?php the_post_format_image(); ?>
    </div>
    <div class="entry-content">
    	<?php the_remaining_content(); ?>
    </div>

    In this case you would NOT need to add "structured-post-formats" support because you're not using the_content() at all. You're using the new the_remaining_content() function.

    So in what I gather from how all this works, is that the logic of removing theme support for a structured post format and expecting the post format UI icon to be removed doesn't quite make sense. By default, there is no theme support for any "structured-post-formats" -- i.e. that has nothing to do with the UI being presented to the user; it's all about fallbacks when outputting in the theme.

    This is all going to be confusing for many, but on the plus side there are are now so many potential options we can do in our themes, just accepting that post formats need to be part of the standard moving forward.

Topic Closed

This topic has been closed to new replies.

About this Topic