• The plugin is working great when i pass ?amp into pages. However, I’d like to have the plugin completely ignored and run custom amp code on certain post types. I’ve tried, but it just returns a 404.

    add_filter( 'amp_skip_post', 'isa_skip_posts', 10, 3 );
    function isa_skip_posts( $skip, $post_id, $post ) {
    	
    	if (get_post_type() == "summary" ) {
            $skip = true;
        }
        return $skip;
    }

    I want to run the following code to call a separate template to render for a post type, but the ampforwp plugin is loading and rendering a 404 page (the 404 loads in the ampforwp amp design). Ideally, just want the plugin to not run so my code below can execute.

    add_filter( 'template_include', 'amp_page_template', 99 );
    
    function amp_page_template( $template ) {
    
    	$the_slug = str_replace("?amp", "", $_SERVER["REQUEST_URI"]);
    
    	$args = array(
    	  'name'        => $the_slug,
    	  'numberposts' => 1,
    	  'post_type'	=> 'any'
    	);
    
    	$my_posts = get_posts($args);
    
    	if( $my_posts ) :
    		global $post;
    		$post = $my_posts[0];
    		setup_postdata( $post);
    
    		if (strpos($_SERVER['REQUEST_URI'],'?amp') !== false) {
    
    			if (get_post_type() == "summary" ) {
    				$template = get_template_directory() .  '/template-parts/amp/amp-master.php';
    			} 
    			
    		}
    		endif;
    		wp_reset_postdata();	
    	return $template;
    }

    Any help would be greatly appreciated.

Viewing 1 replies (of 1 total)
  • Plugin Contributor ampforwp

    (@ampforwp)

    Hi @schuerwm,

    Regarding the AMP on certain post types, You can exclude AMP from your preferred pages from the “Hide AMP Bulk Tool” section. Did you try these options? If not, please try these options to hide the AMP and show certain post types. You can find this option in AMP > Setting > Hide AMP Bulk Tool.

    Regarding the custom template, Here are some steps to create the custom template:

    * First create a folder called as ‘ampforwp’ in your child theme ( Screenshot: https://take.ms/hHsDG ).
    * And in that folder, add the new file which you want to override example page.php (screenshot: https://take.ms/pz0OF ). make sure that swift theme’s file name and new file name should be same.
    * Copy all the code from the page.php of swift theme and paste it in the new file which we’ve named as page.php.
    * And add the extra code which you want to add.

    You can also check this tutorial here: https://ampforwp.com/tutorials/article/create-custom-template-post-type-taxonomy-amp-theme-framework/

    If still, didn’t solve the issue, please contact us directly on [email protected]. Our technical team will assist you there.

    Hope it helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Ignore Plugin on Certain Post Type’ is closed to new replies.