Create a free scripts and styles template within a plugin

It seems a little odd to only offer the admin bar for a page, but the easiest solution I can think of would be to use conditional functions to deregister scripts/styles and create custom template files for this specific page. Unfortunately, you’ll have to figure out all the styles/scripts that are loaded add_action(‘init’, ‘remove_all_the_things’); function … Read more

How to use output buffering in WordPress hooked functions?

TL;DR: After the draft_to_publish hook is executed, the page is redirected, so you won’t see the echoed output. Ref: https://wordpress.stackexchange.com/a/94011/71131 I think the problem is that the draft_to_publish action saves the post, which will call a redirect request to the browser, which loads the edit page from scratch again. Then whatever whatever scripts previously echoed … Read more

What is the proper way to include Bootstrap when executing a shortcode

I also find the typical practice of queuing globally or from inside shortcodes problematic. I had a similar challenge with implementing code highlight on my site — I only wanted scripts and style to load as necessary. I ended up checking content for <pre> tag as condition to output: {% if ‘<pre>’ in get_the_content() %} … Read more

How To Change Post Author Default?

You just create must-use plugin for your multisite instalation (https://codex.wordpress.org/Must_Use_Plugins), hook to post save action there (https://codex.wordpress.org/Plugin_API/Action_Reference/save_post), and inside action callback check if current user is admin/super admin (https://codex.wordpress.org/Function_Reference/is_super_admin), if so, you find current blog user with ‘author’ role (https://codex.wordpress.org/Function_Reference/get_users) and update post (https://codex.wordpress.org/Function_Reference/wp_update_post) with his ID as author ID. At least it is first, … Read more