So I created a wrapper function for wp_enqueue_style() that you can use to pass your CPT name along with the usual enqueue parameters, and it will magically enqueue your style ONLY on the CPT editor page that you specify! Cool huh?įirst off, let’s target the general admin editor pages to run a callback function when either the post.php or post-new.php are loaded. After a bit of experimentation I came up with a solution that I could probably reuse. So, I spent some time looking for a reasonable way that I could enqueue styles that would work for specific CPT’s. It is not necessary to register and then enqueue as when we enqueue a CSS or JS it already. Firstly we will register the CSS or JS, which will not load them but will make them ready for the later use. However this has the side effect of altering the post editor for ALL post types. In this step, we are going to use the above functions in a slightly different approach and will add CSS and JS to a specific page template. I'd like to reuse these functions in some other pages. I have a WordPress page that has a script with a few functions and then another short script that uses them. Will appreciate a few lines of concrete instructions. The solution? Well, it is fairly easy to add custom CSS that will target just the post.php or post-new.php pages in the WordPress admin. I'm new to WordPress, tried first searching for this and found a few related answers, none of which i fully understood. The default height is way to big and so the other meta boxes on this CPT are pushed down the page. The editor for the CPT in question is only ever going to be used to enter a couple of sentences, so it really only needs to have a small height. The possibilities really are endless, and boost the capabilities of WordPress significantly.Īnyway, this post is about an interesting problem I ran into whilst creating my first CPT (custom post type). I really wish I had looked into them sooner, they are so cool. I’ve finally(!) got around to using custom post types, and I’m having a blast. Normally, plugins use wpenqueuescripts hook to enqueue scripts, but here we use a dynamic hook so that chart scripts are added only to plugins admin. Category: Featured, WordPress 3.x Tags: CPT, editor, enqueue, scripts, styles
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |