[Resolved] Filtering customizer options for custom post type

Home Forums Support [Resolved] Filtering customizer options for custom post type

Home Forums Support Filtering customizer options for custom post type

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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;
    }
    #425225
    Tom
    Lead Developer
    Lead Developer

    Try 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;
    }
    #425686
    Han

    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

    #426444
    Tom
    Lead Developer
    Lead Developer

    Ah – I just made an adjustment to the code above. Should work better now πŸ™‚

    #426472
    Han

    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!

    #426906
    Tom
    Lead Developer
    Lead Developer

    That’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 πŸ™‚

    #426936
    Han

    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

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.