Display a function using AJAX

You’re not hooking the function to wp_ajax correctly. You need to replace the my_action part with your action name that you’re using the in AJAX request. In your case it’s display_user_table. You also need to hook it on to wp_ajax_nopriv so that it works for logged out users. Here’s your hook with those changes: add_action(‘wp_ajax_diplay_user_table’, … Read more

Develop function get_template_part in functions.php

get_template_part is echoing the HTML code. and the shortcode function must return the content. then you can try that : function custom_code($attr, $content, $tag) { ob_start(); get_template_part( ‘page’, ‘example’ ); $content = ob_get_clean(); return $content; } add_shortcode( ‘custom’, ‘custom_code’ );

Allow latex in wordpress excerpt

If I’m not mistaken, this could be as simple as add_filter(‘get_the_excerpt’, ‘latex_markup’); if the Latex markup isn’t removed by another filter before that (it shouldn’t, I believe). latex_markup is the function jetpack adds to the list of filters on the_content. It might get interesting when your latex code is at the edge of the excerpt … Read more

Add a new subscriber role using a function

A subscriber has only 1 capability namely: read To create a new (custom)role just add following code-lines in functions.php. Please make back-up first and so on…. When added to functions.php go into the back-end and check if you can add an (new or existing) user to this role. When all is working you can delete … Read more

Changes to functions.php not working

Closing PHP tag and then opening in the next line: Whenever there is something (even space, tab, newline etc.) after a closing PHP tag ?> or before an opening PHP tag <?php, PHP engine considers it as output. So the way your code is, it’ll generate some unnecessary output, that often throws error or warning … Read more

Link Category Description

OK, with the help of a friend I was able to get this done. I ditched the wp_list_bookmarks and went with a combination of get_terms and get_bookmarks. function blogroll_page( $args = array() ) { if(is_page(‘blogroll’)) { if( $terms = get_terms( ‘link_category’, $args = array(‘exclude’ => 16) ) ) { foreach( $terms as $c ) { … Read more

Check is category parent or not from its ID

You can do something like this: function category_has_parent($catid){ $category = get_category($catid); if ($category->category_parent > 0){ return true; } return false; } and use it like this: if (category_has_parent(’22’)){ //true there is a parent category }else{ //false this category has no parent } Update: to check the other way around (if a category has children) you … Read more

Custom function for user register in wp?

Yes you can but you need to include registration.php for validation something like: //Need registration.php for data validation require_once( ABSPATH . WPINC . ‘/registration.php’); $firstname = sanitize_text_field( $form_data[‘firstname’] ); $lastname = sanitize_text_field( $form_data[‘lastname’] ); $username = sanitize_text_field( $form_data[‘username’] ); $email = sanitize_text_field( $form_data[’email’] ); //Add usernames we don’t want used $invalid_usernames = array( ‘admin’ ); … Read more

Cleaner way to access custom fields in code?

I would write a function to handle the monotony of this task. function my_print_meta($id, $key, $alternate=””) { if($value = get_post_meta($id, $key, true)) echo $value; else echo $alternate; } Notice in the function that I only call get_post_meta once and store the value in a variable so that two separate database queries don’t need to be … Read more

Enqueue styles after a plugin

Note that cForms is hooking into wp_head, and you’re attempting to hook into wp_enqueue_scripts. The wp_enqueue_scripts hook is fired inside the wp_head hook (at priority 0, IIRC). So, your stylesheet is being enqueued at wp_head, priority 0, and the cForms stylesheet is being enqueued at wp_head, priority 10. Since it outputs later, it is taking … Read more