• Resolved John Antonacci

    (@johnnya23)


    I am using custom post types to add content to the headers and footers of my site. Unfortunately, your blocks don’t work in this scenario. A filter along this line would be helpful.

    public function get_singular_dynamic_css($post = false)
            {
                $getCSS = '';
                $posts = array();
                if ($post) {
                    //$getCSS = $this->single_stylesheet( $post );
                    $posts[] = $post;
                } elseif (is_singular()) {
                    global $post;
                    $posts[] = $post;
                //$getCSS = $this->single_stylesheet( $post );
                } elseif (is_archive() || is_home() || is_search()) {
                    global $wp_query;
                    if (isset($wp_query->posts)) {
                        /*foreach ( $wp_query->posts as $post ) {
                            $getCSS .= $this->single_stylesheet( $post );
                        }*/
                        $posts = $wp_query->posts;
                    }
                }
                $posts = apply_filters('get_singular_dynamic_css_filter', $posts);
                foreach ($posts as $post) {
                    $getCSS .= $this->single_stylesheet($post);
                }
    
                $output = gutentor_dynamic_css()->minify_css($getCSS);
                return $output;
            }

    does this make sense? does it seem reasonable?

    thanks for a great system.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor codersantosh

    (@codersantosh)

    Hello @johnnya23 ,

    I would like to suggest you to follow similar code structure like Gutentor widgets. See the widget method. The CSS is store on the meta gutentor_dynamic_css. Please try it and let us know if you have further queries.

    Best Regards!

    Thread Starter John Antonacci

    (@johnnya23)

    @codersantosh thanks for the response.

    What you suggest appears to be beyond my coding capacity.

    I guess with 5.7 or whenever block widget areas come along This might be useful.

    thanks,

    Thread Starter John Antonacci

    (@johnnya23)

    Still playing around..

    I get the css with this (I think):

    function jma_ghb_component_css($id = '', $type = '', $return = true)
    {
        if (!$id) {
            return;
        }
        $ghb_args  = array(
                        'p'         => $id,
                        'post_type' => $type,
                    );
        $ghb_query = new WP_Query($ghb_args);
        /*The Loop*/
        $style = $font_str = '';
        if ($ghb_query->have_posts()) {
            while ($ghb_query->have_posts()) {
                $ghb_query->the_post();
                if ($return) {
                    if (get_post_meta(get_the_ID(), 'gutentor_dynamic_css', true)) {
                        $style = get_post_meta(get_the_ID(), 'gutentor_dynamic_css', true);
                    }
                    if (get_post_meta(get_the_ID(), 'gutentor_gfont_url', true)) {
                        $fonts_url = get_post_meta(get_the_ID(), 'gutentor_gfont_url', true);
                        $font_str = '<link id="ghb-gutentor-google-fonts" href="' . esc_url($fonts_url) . '" rel="stylesheet" />';
                    }
                    if ($style) {
                        $style = "<!-- ghb Dynamic CSS -->\n<style type=\"text/css\">\n" . wp_strip_all_tags($style) . "\n</style>";
                    }
                }
                $css_info = get_post_meta(get_the_ID(), 'gutentor_css_info', true);
                if (isset($css_info['blocks']) && is_array($css_info['blocks'])) {
                    Gutentor_WP_Block_Widget::$unique_blocks = array_unique(array_merge(Gutentor_WP_Block_Widget::$unique_blocks, $css_info['blocks']));
                }
            }
        }
        wp_reset_postdata();
        return $style . $font_str;
    }

    but I don’t see how I will get the js. Also not sure if the Gutentor_WP_Block_Widget does anything from the template_redirect hook.

    Plugin Contributor codersantosh

    (@codersantosh)

    @johnnya23 I am not sure which JS you need, you can look on this file register_script_style, also search for wp_enqueue_script to find out the JS you need to add.

    Gutentor_WP_Block_Widget does not use the template_redirect hook.

    oh thank god i find the solution here i waslooking for this plugin last one yea on wordpress and wix now i find it i am looking for this plugin i hope it will be suitable for my new blog you can see here Hidethatfat

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Filter for get_singular_dynamic_css’ is closed to new replies.