Okay
  Public Ticket #3430010
Generate Dynamic Styles for CPT and Archive template
Closed

Comments

  •  2
    Aris started the conversation

    Hello,

    we have the salient theme active and use the WPBakery as an editor.

    We have created a custom post type and selected the role manager capability to use the WPbakery as an editor for the custom post type and use the custom blocks which come with the salient theme.

    Now the issue is, that the same element has the proper padding, margin, color, etc generated by NectarElDynamicStyles::generate_styles() for pages/posts. But not for the pages created by Custom post types.

    We noticed that the method NectarElDynamicStyles::generate_styles(), works around with the custom meta fields created for pages/posts within the salient core. And since we don't have the same meta fields available for the pages created using the Custom Post Type, the NectarElDynamicStyles::generate_styles() method is not working for the CPT.

    Is there any way, we can assign the meta fields to the CPT as well, so that we have the dynamically generated styles apply to the pages created for CPT using the WPBakery blocks?

    Please let us know.

  •  8,939
    Tahir replied

    Hey Again,

    Could you allow us to log in to your website backend dashboard so we can check on this for you more?. We are gonna need the username and password of admin user as well as the login url.

    Thanks.


    ThemeNectar Support Team 

  •   Aris replied privately
  •  8,939
    Tahir replied

    Hey Again,

    This should help: https://themenectar.com/docs/salient/metabox-cpt 

    Thanks.


    ThemeNectar Support Team 

  •   Aris replied privately
  •  8,939
    Tahir replied

    Hey Again,

    Unfortunately, we can help further troubleshoot it without taking a look at how the Custom Post Type content is displayed in the Backend. 

    Thanks.


    ThemeNectar Support Team 

  •   Aris replied privately
  •  1,086
    ThemeNectar replied

    Hey Aris, is looks like your custom post type is getting skipped from the dynamic style generation because it's set as an "archive", and archives get skipped from that generation by default. 

    If you can't change your CPT setup, you can manually force the CSS generation for your post type by adding the following snippet to your Salient child theme functions.php:

    add_action( 'wp_enqueue_scripts', 'salient_child_enqueue_dynamic_cpt_styles', 100);
    function salient_child_enqueue_dynamic_cpt_styles() {
        global $post;
        if( 'YOUR_CPT_SLUG' == get_post_type() && isset($post->post_content) ) {
           $nectar_cpt_specific_dynamic_css = NectarElDynamicStyles::generate_styles($post->post_content);
           wp_add_inline_style( 'dynamic-css', $nectar_cpt_specific_dynamic_css );
        }
    }
    

    Kind regards

  •  2
    Aris replied

    Hi Tahir, Thank you for your support. I tried it and it worked. now the page is getting the dynamic inline css applied to it. your help is much appreciated.


    Thank you!

  •  2
    Aris replied

    Hi Tahir, We noticed that even after the dynamic inline CSS is applied after using your code, somehow the dynamic style is still rendering the wrong output.

    for example, if we choose the "Column Padding" in the "Column setting" of Wpbakery builder for 4%, the inline dynamic style generated is 2%. And for any value I choose, the style is always for 2% class and then it doesn't work.

    I have tried to find the solution but unable to do so. 

    My hunch is that the following piece of code is working only for the first the_content() method. and ignore other available the_content() on the page.

    please check the attached screenshot.


    Thank you!


    Attached files:  4%-column-padding.png
      wpbakery-column-padding.png

  •   Aris replied privately
  •  8,939
    Tahir replied

    Hey Again,

    The previous user/pass does not seem to work.

    Could you allow us to log in to your website backend dashboard so we can check on this for you more?. We are gonna need the username and password of admin user as well as the login url.

    Thanks.


    ThemeNectar Support Team 

  •   Aris replied privately
  •  8,939
    Tahir replied

    Hey Again,

    Just added in this code to generate the dynamic styles for the content in the archive template.

    Thanks.


    ThemeNectar Support Team 

  •  2
    Aris replied

    Hi Tahir,

    sorry, I don't understand. Did you update the code in this thread? because it's the same as the previous one. Or did you miss writing the code here?

    Or did you added the code on the site itself? if so, please let me know where.

    Thank you.

  •  8,939
    Tahir replied

    Hey Again,

    My Bad, The Screenshot does not seem to have gotten attached. I have already added in the code to output the stylesheet in the Archive template. See screenshot: 


    6753705799.pngThanks 


    ThemeNectar Support Team 

  •  2
    Aris replied

    Thank you again. I just tested it and It worked as expected. As always appreciate your help on the matter.