• I am currently trying to customize the display of my posts that gets embedded on other sites.

    I am able to have my custom template file through the embed_template filter but I can’t successfully enqueue scripts if I am using the embed template. The filter enqueue_embed_scripts works without problem if I am not using the embed_template filter. I also tried the embed_head and embed_footer hooks but I can’t get them to work as well.

    This is my current code:

        class Test_Embed {
        
            public function __construct() {
    
                add_action( 'enqueue_embed_scripts', array( $this, 'embed_styles' ) );
                add_filter( 'embed_template', array( $this, 'my_embed_template' ) );     
    
            }
        
            public function embed_styles() { 
    
                wp_enqueue_script( 'video-js', plugin_dir_url( dirname( dirname( __FILE__) ) ) . 'public/js/vendor/video-js/7.2.4/video.js', '', '', true );
                wp_enqueue_script( 'fancybox3', plugin_dir_url( dirname( dirname( __FILE__) ) ) . 'public/js/vendor/fancybox/3.5.2/jquery.fancybox.min.js', array( 'jquery' ), '3.5.2', true );
            	wp_enqueue_style( 'myb-css', plugin_dir_url( dirname( dirname( __FILE__) ) ) . 'public/css/public.css', array(), '', 'all' );
            }
    
           public function my_embed_template( $template ) {
    
                if ( 'custom-post' === get_post_type() ) {
                    return dirname( __FILE__ ) . '/templates/my-template.php'; 
                }
        
                return $template;
    
            }
    
        }
    
        new Test_Embed;

    Is there something I missed in enqueuing scripts to the custom embed template I am using?

    • This topic was modified 6 years, 4 months ago by jadeivee.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    More than likely your embed template is not firing the requisite actions. Somewhere there should be a line similar to
    do_action( 'embed_head' );
    in the <head> section of the template.
    For examples of basic embed templates, look at the default templates at /wp-includes/theme-compat/

Viewing 1 replies (of 1 total)
  • The topic ‘How to make enqueue_embed_scripts work with the embed_template filter’ is closed to new replies.