Redeclare/Change Slug of a Plugin’s Custom Post Type

Yes, this is possible, but if the plugin is creating a custom post type using the rewrite => array(‘slug’ => ‘post_type’) parameter, then it’s not likely that you’re going to be able to replace the slug. Whenever custom post types are created, URL rewrite rules are written to the database. Depending on which action triggers … Read more

Why use if function_exists?

Checking to see if built in WordPress functions exist before calling them is for backward compatibility which IMHO is not needed. So if you see if ( function_exists( ‘register_nav_menus’ ) ) the theme author is supporting versions earlier than 3.0. You still sometimes see if ( function_exists( ‘dynamic_sidebar’ ) ) Why? I couldn’t tell you … Read more

Where do I put the code snippets I found here or somewhere else on the web?

Whenever you find a piece of code without clear installation instructions it is probably a plugin. The example you gave is a good one, because that is the most common case: add_action(‘template_redirect’, ‘remove_404_redirect’, 1); function remove_404_redirect() { // do something } To use such a snippet, put it into a plugin: Create a new file, … Read more

remove empty paragraphs from the_content?

WordPress will automatically insert <p> and </p> tags which separate content breaks within a post or page. If, for some reason, you want or need to remove these, you can use either of the following code snippets. To completely disable the wpautop filter, you can use: remove_filter(‘the_content’, ‘wpautop’); If you still want this to function … Read more

Changing Admin Menu Labels

Here’s the process to change the labels (I changed posts to “contacts” in my example) function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = ‘Contacts’; $submenu[‘edit.php’][5][0] = ‘Contacts’; $submenu[‘edit.php’][10][0] = ‘Add Contacts’; $submenu[‘edit.php’][15][0] = ‘Status’; // Change name for categories $submenu[‘edit.php’][16][0] = ‘Labels’; // Change name for tags echo ”; } function change_post_object_label() { global … Read more

How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?

The way to do this is to use the ‘admin_enqueue_scripts’ hook to en-queue the files you need. This hook will get passed a $hook_suffix that relates to the current page that is loaded: function my_admin_enqueue($hook_suffix) { if($hook_suffix == ‘appearance_page_theme-options’) { wp_enqueue_script(‘my-theme-settings’, get_template_directory_uri() . ‘/js/theme-settings.js’, array(‘jquery’)); wp_enqueue_style(‘my-theme-settings’, get_template_directory_uri() . ‘/styles/theme-settings.css’); ?> <script type=”text/javascript”> //<![CDATA[ var template_directory … Read more