- This topic has 6 replies, 2 voices, and was last updated 6 years ago by
Han.
-
AuthorPosts
-
November 15, 2017 at 6:08 am #424890
Han
Hi,
I have a custom post type Cases and want the single case post to look a bit different from a single blog post. While browsing the forums I found a few things. So I was able to remove the sidebar.
But I would like to do more.I tried the code below combined from a few forum posts. It does change the image size. That works.
But is not changing the post_image_position and post_image_alignment.Can you have a look what to improve?
Thanks, Han
add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' ); function tu_variable_image_sizes( $atts ) { // Set up our conditional if ( is_singular('cases') ) { $atts[ 'width' ] = 700; $atts[ 'height' ] = 700; $atts[ 'crop' ] = false; $atts[ 'post_image_position' ] = 'post-image-below-header'; $atts[ 'post_image_alignment' ] = 'post-image-aligned-left'; } // Return our options return $atts; }
November 15, 2017 at 11:24 am #425225Tom
Lead DeveloperLead DeveloperTry this:
add_filter( 'option_generate_blog_settings', 'tu_cpt_featured_image_options' ); function tu_cpt_featured_image_options( $options ) { if ( is_singular( 'cases' ) ) { $options['single_post_image_position'] = 'below-title'; $options['single_post_image_alignment'] = 'center'; } return $options; }
November 16, 2017 at 1:33 am #425686Han
I tried this but that had not the desired effect. The single post image was still above the title and centered in stead of aligned left.
Also, this code messed up my blog archive settings. Somehow other customizer settings get lost when I add this code in functions.php.
Is there another way to achieve this?
Thank you,
Han
November 16, 2017 at 9:47 pm #426444Tom
Lead DeveloperLead DeveloperAh – I just made an adjustment to the code above. Should work better now π
November 16, 2017 at 11:03 pm #426472Han
Ah great, that is perfect. I’m not sure I can tell the difference. Was a typo I guess, that I did not notice?
Anyway, this works perfect. πOn the same note, is there somewhere an overview of options and their values?
I would like to do more stuff like this. Or let me put it differently. What is the easiest way to find out what options and values are available?Thanks a lot!
November 17, 2017 at 9:15 am #426906Tom
Lead DeveloperLead DeveloperThat’s actually a WordPress filter which works with the option name: https://codex.wordpress.org/Plugin_API/Filter_Reference/option_(option_name)
I need to build a docs article explaining it, as well as list the possible option names etc.. It’s very powerful π
November 17, 2017 at 9:34 am #426936Han
Ah yes that would be nice. This makes it really flexible to change some stuff here and there for a custom post type. Great feature!
Thanks -
AuthorPosts
- You must be logged in to reply to this topic.