• Resolved signisagency

    (@signisagency)


    Hello,

    For a News site, I would need to disable AMP by default on all articles, leaving me the choice to choose which ones will be displayed in AMP version later.
    To do this I used this code found on the documentation by replacing “xyz-review” with “post”:

    add_filter( 'amp_post_status_default_enabled', function( $default, $post ) {
    	if ( 'xyz-review' === $post->post_type ) {
    		$default = false;
    	}
    	return $default;
    }, 10, 2 );

    Except that, in the wordpress back-panel the articles seem to be deactivated but when I test with the URL “?amp” the articles load well in AMP and do not seem to be deactivated.
    Do I have to do something more? Is it a bug?

    Thank you in advance.
    Sincerely.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    I’m not able to reproduce this issue.

    Here is the code I’m using: https://gist.github.com/westonruter/c9c203d6b938aa2e928fca8369706149

    When I publish a “book” post type, I do not see any amphtml link in the frontend and accessing the AMP version redirects to the non-AMP version. Also, the post type shows AMP as disabled when I create it, as expected.

    Are you sure that you are accessing the actual custom post type on the frontend? You might need to flush your rewrite rules when adding a new post type.

    Thread Starter signisagency

    (@signisagency)

    Thank you for the answer.
    I don’t want to create a new post type but use the WordPress post type “post” (including all the articles already present) with this filter and disabled AMP on this post type! Basically, disabled (by default) AMP on all articles of the site, retroactively and for future ones.
    But, I have the impression that the articles already posted are not affected by this filter.

    Plugin Author Weston Ruter

    (@westonruter)

    It works for for me with the regular post type as well, using this code:

    add_filter(
    	'amp_post_status_default_enabled',
    	function( $default, $post ) {
    		if ( 'post' === $post->post_type ) {
    			$default = false;
    		}
    		return $default;
    	},
    	10,
    	2
    );
    
    Thread Starter signisagency

    (@signisagency)

    Thank you !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Disabled AMP by default for posts’ is closed to new replies.