Adding tables to the WordPress Editor

updated with more explanation If you want to build this into your theme – this tutorial for adding some code to functions.php will work. Keep in mind you will have to download TinyMCE and add files to /wp-includes for this to work. That’s because “table management” is a plugin for TinyMCE and doesn’t ship with … Read more

file.php not loaded?

OK, so there’s a bunch of admin functions in wp-admin/includes. These are loaded at some point between the loading of the theme’s functions.php and the admin_init hook. But that are ONLY loaded for admin-side pages. They are not loaded for front-end pages or AJAX calls. If you want to use these functions in front-end pages … Read more

define css class in functions.php

First off, the origin of the data (WordPress theme options) aside, this question is pretty much about generic PHP and CSS. That being said, here’s how: PHP Stylesheet Add a new file to your theme, call it “dynamic_styles.php” or the like. Note that while it will contain mostly CSS, you give it a .php file … Read more

Different registration form for different roles

I don’t know how “Cimy User Extra Fields” works, but you can add fields to the user registration page with: function extra_user_profile_fields_wpse_92164() { echo ‘<label for=”extra_field”>’,_(“Extra Field”).'</label>’; echo ‘<input type=”text” name=”extra_field” value=”” size=”25″ id=”extra_field” />’; } add_action( ‘register_form’, ‘extra_user_profile_fields_wpse_92164’ ); To switch subscriber types you could pass in $_GET parameters, which is how the default … Read more

Enqueueing scripts selectively & activation where needed

If you’re only enqueueing scripts when they’re needed, you can check in JS if the plugin’s namespace exists before trying to use it: if( $.fn.slider ) { $(‘#slider’).slider(); } or another option is to pass some script vars via wp_localize_script: $wpa_script_data = array( ‘is_front_page’ => is_front_page(), ‘slider_options’ => array( ‘speed’ => 6000 ) ); wp_localize_script( … Read more

the_post_thumbnail issues

the_post_thumbnail() prints the HTML immediately. Use get_the_post_thumbnail() instead to get the HTML into your string. $content .= ‘<div class=”thumbnail”>’ . get_the_post_thumbnail( null, “home-post-thumbnail”) . ‘</div>’;

Defining multiple categories for showing latest posts

This is incorrect formatting of a PHP array: ‘cat’ => ‘4’, ‘5’, ‘6’, ‘7’ Use category__in and pass an array of category IDs: $args = array( ‘posts_per_page’ => 4, ‘category__in’ => array( 4, 5, 6, 7 ) ); See WP_Query for all valid parameters and how to format them correctly.

Perform function on publish AND save (not just save)

Instead of taking meta values from get_post_meta function take it from $postarr array because when initial publishing of the post there isn’t any values for event_datestart and venue_name in database and it returns empty string. Updated Code : function set_event_title( $data , $postarr ) { if($data[‘post_type’] == ‘event’) { $getdate = $postarr[‘event_datestart’]; // Replace event_datestart … Read more