• Resolved jeantardelli

    (@jeantardelli)


    Hello there!

    First of all, thank you for the great plugin and the great documentation.

    I’m using read mode, legacy template and would like to know if I can override the head HTML attribute of the AMP post somehow using php.

    There is an optimisation plugin that is adding a little JavaScript on AMP pages (I already created a ticket with them, but also wanted to know if I can manage this with php).

    For example, given the following document:

    <!DOCTYPE html>
    <html amp transformed="self;v=1" i-amphtml-layout="" i-amphtml-no-boilerplate="">
    
    <head><script FOO>undesired js</script> <meta charset="utf-8"><meta name="viewport" content="width=device-width,minimum-scale=1"><link rel="preconnect" href="https://cdn.ampproject.org"><style amp-runtime="" i-amphtml-version="012201141909003">
    … 

    Is is possible to do something like this using some available AMP function to remove the undesired js?

    <?php
    $html = file_get_contents(URL);
    $content = preg_replace('/<script FOO>.*<\/script>', '', $html);
    return $new_content
    ?>

    Or any other way to remove it using php? Any ideia is highly appreciated 🙂

    Thanks

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @jeantardelli

    Thank you for the support topic, The AMP pages are already optimized pages and do not need extra plugins for optimizations

    I will recommend suppressing the plugin using the AMP plugin setting for plugin Suppression.

    Hope this helps!

    Thread Starter jeantardelli

    (@jeantardelli)

    Hello Milind!

    How are you? Thank you for you fast reply.

    I could find the inconsistency here. The fact is that the WP-Meteor plugin is capable of know if it is a AMP page, and also automatically hide its scripts from such pages.

    The problem was that I had surpressed it, thus, ironically, the wp-meteor added the script in such pages.

    So for the record, if anyone is using WP-Meteor with AMP do not surpress the plugin.

    Thank you for your time, though.
    And sorry for the confusion!

    • This reply was modified 4 years, 4 months ago by jeantardelli.
    • This reply was modified 4 years, 4 months ago by jeantardelli.
    • This reply was modified 4 years, 4 months ago by jeantardelli.
    Plugin Support Milind More

    (@milindmore22)

    Hello @jeantardelli

    It looks like the script may be added post-AMP DOM generation, which means no hook or filter from the AMP plugin can stop that from happening.

    You can however try to use wp-meteor-frontend-rewrite filter to process the buffer

    eg: sample/demo code not be used as it is, need editing as per requirement

    add_filter( 'wp-meteor-frontend-rewrite', function( $buffer ) {
    
    	if ( $buffer ) {
    		// take only first 50 character from buffer.
    		$short_buffer = substr( $buffer, 0, 50 );
    		// check if amp attribute is present in buffer <html amp>.
    		if ( strpos( $short_buffer, 'amp' ) !== false ) {
    			// if amp attribute present remove script.
    			$buffer = preg_replace( '/<script FOO>.*<\/script>', '', $buffer );
    		}
    	}
    	return $buffer;
    } );

    I will recommend contacting WP Meteor plugin on how you can use the above filter

    Hope this helps!

    Thread Starter jeantardelli

    (@jeantardelli)

    Thank you, Milind!

    I was able to find the issue. But as I edited the message you did not see.

    WP-Meteor is capable to identify it is a AMP page. The thing is just let the wp-meteor active, otherwise will add js scripts on AMP posts/pages.

    But thank you very much for your time and help!
    And sorry for the confusion!

    Plugin Support Milind More

    (@milindmore22)

    Glad to know removing it from Suppression worked for you, I’ll mark this as resolved Open a new support topic if you face further issues, also feel free to leave a plugin review, we would love to hear your feedback.

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

The topic ‘Override HTML Tags’ is closed to new replies.