How to set the default value as the saved value once a form of widget is saved?

You need a corresponding function UPDATE to complete this. See the Widgets API on the codex: http://codex.wordpress.org/Widgets_API Below is their example. /** * Adds Foo_Widget widget. */ class Foo_Widget extends WP_Widget { /** * Register widget with WordPress. */ function __construct() { parent::__construct( ‘foo_widget’, // Base ID __(‘Widget Title’, ‘text_domain’), // Name array( ‘description’ => … Read more

Extending a theme: build new features as plugin or core modules?

If you’re going to want to mix-and-match these modules, I would suggest developing them as plugins or using a plugin such as Code Snippets to separate your modules, making them easier to work on, expand upon, and deactivate/activate. Either way, separating your modules from your theme will make customizing deployments faster while increasing the organization … Read more

Where should I store disabled plugins?

I don’t think you need an extra directory for storing your disabled plugins. Better keep them there default location (/plugins/) and whenever you need to reactive just simple one click away! Or, if you think that plugin doesn’t help you in future, just DELETE it!

Hook on creating a menu entry?

If you check out the source, you find the following actions related to the modifications of the navigational menus: Update: /** * Fires after a navigation menu has been successfully updated. * * @since 3.0.0 * * @param int $menu_id ID of the updated menu. * @param array $menu_data An array of menu data. */ … Read more

Hook Scripts and Styles in WordPress

You have two flaws in your code, one is a syntax error, the other one is the wrong hook. Firstly, wp_enqueue_scripts is the hook used to enqueue scripts and styles for front end use. When you need to enqueue scripts and styles for the backend, you should use the admin_enqueue_scripts hook Secondly, you are missing … Read more

Embed PDF into wordpress

The only reliable cross browser solution is to embed the .pdf in a iframe. add_filter(‘media_send_to_editor’, ‘my_pdf_embed’, 20, 3); function my_pdf_embed($html, $id) { $attachment = get_post($id); //fetching attachment by $id passed through $mime_type = $attachment->post_mime_type; //getting the mime-type if ($mime_type == ‘application/pdf’) { //checking mime-type $src = wp_get_attachment_url( $id ); //change the size to your liking … Read more

Posts to have category specific sidebars with the widgets

Create a child theme (if you haven’t already) and register two sidebars: function wpse_151695_register_sidebars() { register_sidebar( array( ‘name’ => ‘News’, ‘id’ => ‘sidebar-news’, ) ); register_sidebar( array( ‘name’ => ‘Blog’, ‘id’ => ‘sidebar-blog’, ) ); } add_action( ‘widgets_init’, ‘wpse_151695_register_sidebars’ ); Then in your sidebar.php: if ( is_singular() ) { // For single posts, show the … Read more