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

How Can I add a menu to the theme from withen the function.php file

I think your current call to wp_nav_menu() may be echoing the menu when the code is seen and not returning it in the function. Try this call: wp_nav_menu( array( ‘theme_location’ => ‘legal_footer_navigation’, ‘echo’ => false, ) ); If that works, you can also probably remove the echo parameter from the register_nav_menus() call.

WordPress Check User Role Function (multiple roles)?

if ( wpse_99666_check_user_roles( array( ‘customrole’, ‘author’ ) ) ) _e( “You’ve got access dude!”, ‘appthemes’ ); else _e( ‘Sorry man, no luck.’, ‘appthemes’ ); /** * Checks if a particular user has one or more roles. * * Returns true on first matching role. Returns false if no roles match. * * @uses get_userdata() * … Read more

how to add_filter to non hook function

Assuming that this– add_filter( ‘kandombe_theme_thumb’, ‘kandombe_lazy_loads’);— is the line/hook you are talking about. You don’t hook to functions. That is not how it works. Hooks have to be intentionally created with apply_filters or do_action. Your code would have to be written like this for that to work: function kandombe_theme_thumb($id, $width, $height, $align=”) { //some code … Read more

Creating a custom wordpress widget and stopping js from running twice(once in active widget once in widget selector)?

Use wp_enqueue_script. You assign a name to your js file when enqueued, and it will stop a file from being enqueued multiple times. Right now your JS is simple enough, but as it gets more complex, it’s better to have it outside in it’s on .js file. add_action( ‘wp_enqueue_scripts’, ‘add_my_js’ ); function add_my_js() { wp_enqueue_script( … Read more