New Landing How can we help? Themeforest Theme Support Flexform inconsistent url references

Viewing 15 posts - 1 through 15 (of 18 total)
  • Posted in: Flexform
  • #196531
    Bitedge
    Member
    Post count: 345

    Hi guys,

    https://gtmetrix.com/reports/www.bitedge.co/4dIjYW8U

    Tell us

    “The following resources have identical contents, but are served from different URLs. Serve these resources from a consistent URL.

    http://www.bitedge.co/wp-content/themes/flexform-child/style.css
    http://www.bitedge.co/wp-content/themes/flexform-child/style.css?ver=4.2.2”

    https://premium.wpmudev.org/forums/topic/how-to-fix-inconsistent-url-references

    Tells us its probably caused by a plugin, but its not I tested that.

    Removing

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 100 );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
    }

    From functions.php does solve the problem and break the sites layout. The other file of interest is /wp-includes/script-loader.php

    How can we call this style sheet from a consistent URL? Thanks

    #196539
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please provide me wordpress admin login detail after installing WPIDE plugin.
    Thanks
    Mohammad

    #196574
    Bitedge
    Member
    Post count: 345

    Thanks, before I do that I have found that comenting out

    132 wp_register_style('main-css', get_stylesheet_directory_uri() . '/style.css', array(), NULL, 'screen');

    from parent theme function.php resolves the problem and does not have any negative effects I can see on the site. What do we lose by keeping that commented out? Was that your plan? A problem is that it will be overridden at the next theme update but those are very infrequent with flexform.

    I am told this could be used in the child theme to achieve that and not be overridden by the next update but I don’t understand it myself.

    https://codex.wordpress.org/Function_Reference/wp_dequeue_style

    #196582
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    As you have you discovered, the best way to remove a registered style is by wp_dequeue_style.

    You will need to place this in your child theme functions.php file for it to be update proof.

    A typical example:

    if( !function_exists ('your_prefix_dequeue_theme_styles') ) {
    	function your_prefix_dequeue_theme_styles(){
    	    wp_dequeue_style( 'main-css' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'your_prefix_dequeue_theme_styles' );

    – David.

    #196588
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    You dont need to comment this code and remove the code of child theme functions.php file. You need to insert this code at style.css of child theme. Its the way to load the parent theme style.css file through child theme.

    @import url("../flexform/style.css");

    Thanks
    Mohammad

    #196595
    Bitedge
    Member
    Post count: 345

    @ Mohammad Importing css is an even worse practice than inconsistent urls and adding that as you suggest does not solve the inconsistent URLs.

    @ David could you please fill out that typical example with the exact code I need in this case? Thanks

    #196604
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    Q1

    When you mention inconsistent URL’s are you referring to this ?ver=4.2.2 being added to the URL? If so, that is just your WordPress version, a $version parameter that is added to the URL by default by WordPress. In your function you have NULL if you replace that with a custom number that could represent the CSS version it will change the parameter value. Ex: change NULL to '1.0.0'.

    $version – “String specifying the stylesheet version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the stylesheet.”

    Reference & docs are here: https://codex.wordpress.org/Function_Reference/wp_enqueue_style#Parameters

    Q2

    Have you added the supplied code to your child theme, that should work? That will remove the CSS enqueued as main-css. You can change that parameter to any other enqueued CSS names to remove those also.

    Thanks,
    David.

    #196605
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    You need to remove code at functions.php of style.css file loading.
    Thanks
    Mohammad

    #196606
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    try to add this one in the functions.php of your child theme, and remove the import from the style.css of the child theme.

    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
    }

    Let us know if it worked.

    edited- didnt realised my colleagues already replied.

    -Rui

    #196624
    Bitedge
    Member
    Post count: 345

    @ David as per the OP the problem is Gmetrix https://gtmetrix.com/reports/www.bitedge.co/4dIjYW8U righly says

    “The following resources have identical contents, but are served from different URLs. Serve these resources from a consistent URL.

    http://www.bitedge.co/wp-content/themes/flexform-child/style.css
    http://www.bitedge.co/wp-content/themes/flexform-child/style.css?ver=4.2.2”

    @ Rui

    That change caused

    Fatal error: Cannot redeclare theme_enqueue_styles() (previously declared in /home/bitcoin7/staging/1/wp-content/themes/flexform-child/functions.php:11) in /home/bitcoin7/staging/1/wp-content/themes/flexform-child/functions.php on line 32

    #196627
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    “The following resources have identical contents, but are served from different URLs. Serve these resources from a consistent URL.”

    – Yes, that is because you are loading multiple instrances of the same stylesheet:

    <link rel='stylesheet' id='main-css-css' href='http://www.bitedge.co/wp-content/themes/flexform-child/style.css' type='text/css' media='screen' />
    <link rel='stylesheet' id='parent-style-css' href='http://www.bitedge.co/wp-content/themes/flexform/style.css?ver=4.2.2' type='text/css' media='all' />
    <link rel='stylesheet' id='child-style-css' href='http://www.bitedge.co/wp-content/themes/flexform-child/style.css?ver=4.2.2' type='text/css' media='all' />

    Please deque this one main-css-css.

    Thanks.

    #196628
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    just change the function name like this

    add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_styles' );
    function child_theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
     
    }

    -Rui

    #196762
    Bitedge
    Member
    Post count: 345

    @ David “Please deque this one main-css-css.” Is not helpful unless you tell me how

    @ Rui that solved the inconsistent URL problem but it changed the sites fonts or font weight and thickness as per screenshots so no good.

    Attachments:
    You must be logged in to view attached files.
    #196790
    David Martin – Support
    Moderator
    Post count: 20834

    Hi,

    Using the above code and CSS name ID provided, you would use this in your child theme functions.php file.:

    if( !function_exists ('your_prefix_dequeue_theme_styles') ) {
    	function your_prefix_dequeue_theme_styles(){
    	    wp_dequeue_style( 'main-css-css' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'your_prefix_dequeue_theme_styles' );

    This will remove the stylesheet <link rel='stylesheet' id='main-css-css' href='http://www.bitedge.co/wp-content/themes/flexform-child/style.css' type='text/css' media='screen' />

    – David.

    #196910
    Bitedge
    Member
    Post count: 345

    With that in place we still get

    “The following resources have identical contents, but are served from different URLs. Serve these resources from a consistent URL.

    http://www.bitedge.co/wp-content/themes/flexform-child/style.css
    http://www.bitedge.co/wp-content/themes/flexform-child/style.css?ver=4.2.2&#8221;

    did you mean to change “your_prefix” to something other than “your_prefix” if so what?

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.