How to set permalink structure via functions.php

You can set the permalink structure by calling on the set_permalink_structure() method of the global $wp_rewrite object. add_action( ‘init’, function() { global $wp_rewrite; $wp_rewrite->set_permalink_structure( ‘/%year%/%monthnum%/%postname%/’ ); } ); Here’s a PHP < 5.3 version of the code in case you’re getting errors. function reset_permalinks() { global $wp_rewrite; $wp_rewrite->set_permalink_structure( ‘/%year%/%monthnum%/%postname%/’ ); } add_action( ‘init’, ‘reset_permalinks’ );

Adding a div to wrap widget content after the widget title

In addition to Toscho’s answer here’s what you need for a robust solution: // if no title then add widget content wrapper to before widget add_filter( ‘dynamic_sidebar_params’, ‘check_sidebar_params’ ); function check_sidebar_params( $params ) { global $wp_registered_widgets; $settings_getter = $wp_registered_widgets[ $params[0][‘widget_id’] ][‘callback’][0]; $settings = $settings_getter->get_settings(); $settings = $settings[ $params[1][‘number’] ]; if ( $params[0][ ‘after_widget’ ] == … Read more

How can I display a menu on certain pages only?

That’s a nice option, but I agree with sri, right now it really depends on your theme. You can do a work-around through is_page(). You need to write something like this on your page.php theme file: <?php if (is_page(‘projects’)) { if ( is_active_sidebar( ‘sidebar-navigation’ )) { dynamic_sidebar( ‘sidebar-navigation’ ); } } ?> If you want … Read more

WordPress API Menu/Submenu Order

Here’s an example; First to figure out the order of the sub menu items based upon its array key you can do a var_dump on the $submenu global variable which will output the following; (I’m using the Posts menu and sub menu as an example) //shortened for brevity…. [“edit.php”]=> array(6) { [5]=> array(3) { [0]=> … Read more

Using classes instead of global functions in functions.php

Using a class for encapsulation is a very common approach by a number of developers for plugins. I do this, and I do find it cleaner. But for plugins. Themes are more procedural by nature. We don’t do it for default WordPress themes because it raises the barrier to entry. The functions are quite simple. … Read more

How do I add version control to my workflow?

First of all, you need to recognize that there are two workflows here: yours and your client. Your Workflow Receive PSD Code HTML/CSS Code WordPress template Deploy theme to live WordPress site Their Workflow Devise required changes and email you Write posts Upload photos The Issue Implementing version control here has absolutely nothing to do … Read more

How to store widget fields data as an array?

You have to collect multiple fields under the same name like this … name=”collect[1]” name=”collect[2]” … and adjust your widget logic to this. Here is a very simple demo widget: <?php # -*- coding: utf-8 -*- /* Plugin Name: Store Options as array */ add_action( ‘widgets_init’, array ( ‘T5_Array_Options_Widget’, ‘register’ ) ); class T5_Array_Options_Widget extends … Read more