• Resolved lowestofthekeys

    (@lowestofthekeys)


    (Please refer to imgur screenshot for context)

    I am wondering if there is a function we can add to WordPress that automatically sets AMP to “enabled” on new posts.

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • @lowestofthekeys thanks for the topic! Under AMP > General, there is a Supported Templates section where you can select Posts as a content type to serve AMP by default (you can also choose to support all templates as AMP). That should enable the toggle on new posts.

    Thread Starter lowestofthekeys

    (@lowestofthekeys)

    Hi Renee,

    I have that set already.

    Currently AMP is set to “disabled” on any new posts. I’m wondering if there is a way to change it to “enabled” automatically anytime someone creates a new post.

    Plugin Author Weston Ruter

    (@westonruter)

    @lowestofthekeys Are you perhaps looking for the amp_post_status_default_enabled filter?

    You can disable AMP for new posts by default by adding this to your custom theme’s functions.php or a custom plugin:

    add_filter( 'amp_post_status_default_enabled', '__return_false' );

    If you want to default old posts to be disabled but default new posts (starting this year) to be enabled, this would be an option (untested):

    add_filter( 
    	'amp_post_status_default_enabled', 
    	function ( $enabled, $post ) {
    		return get_post( $post )->post_date > '2020-01-01'; 
    	},
    	10,
    	2
    );
    Thread Starter lowestofthekeys

    (@lowestofthekeys)

    Ha, that worked perfectly. I just tested this via functions.php and any time I generate a new post, the AMP option is enabled (the option is disabled on the older posts).

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘AMP Automatically Enabled on New Posts’ is closed to new replies.