admin管理员组文章数量:1130349
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_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?
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_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?
Share Improve this question edited Nov 9, 2018 at 11:46 Jeda Dragon asked Nov 9, 2018 at 11:33 Jeda DragonJeda Dragon 1237 bronze badges 2- It looks like you're trying to use Fancybox? Keep in mind that the embedded post is inside an iframe, and you're not going to be able to launch a lightbox outside the bounds of that post preview. – Jacob Peattie Commented Nov 9, 2018 at 11:45
- Thanks! Though it is not really my main concern for now as I am not able to enqueue and CSS and JS files. – Jeda Dragon Commented Nov 9, 2018 at 11:47
1 Answer
Reset to default 1It turns out that I just overlooked adding the do_action( 'embed_head' ) and do_action( 'embed_footer' ) in the template file that I have.
Teehee!
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_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?
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_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?
Share Improve this question edited Nov 9, 2018 at 11:46 Jeda Dragon asked Nov 9, 2018 at 11:33 Jeda DragonJeda Dragon 1237 bronze badges 2- It looks like you're trying to use Fancybox? Keep in mind that the embedded post is inside an iframe, and you're not going to be able to launch a lightbox outside the bounds of that post preview. – Jacob Peattie Commented Nov 9, 2018 at 11:45
- Thanks! Though it is not really my main concern for now as I am not able to enqueue and CSS and JS files. – Jeda Dragon Commented Nov 9, 2018 at 11:47
1 Answer
Reset to default 1It turns out that I just overlooked adding the do_action( 'embed_head' ) and do_action( 'embed_footer' ) in the template file that I have.
Teehee!
本文标签: embedHow to make enqueueembedscripts work with the embedtemplate filter
版权声明:本文标题:embed - How to make enqueue_embed_scripts work with the embed_template filter 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749195202a2330859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论