Check from functions.php if function exists in footer.php

You should not declare functions in your templates. The templates are for outputting content. The function_exists() will check if the function is declared before the function_exists() call, not after it, and templates are loaded after functions.php file, since you can control them by using the template_redirect filter. Declare your function in your theme’s functions.php file, … Read more

Fetching Initials of the Commentator in the WordPress Website

Here is function that return you the comment author initials by the comment id function get_comment_author_initials($comment_id) { $author = get_comment_author($comment_id); $words = explode(” “, $author); $initials = null; foreach ($words as $w) { $split = mb_str_split($w); // to cover unicode char $initials .= $split[0]; } return $initials; } function mb_str_split( $string ) { return preg_split(‘/(?<!^)(?!$)/u’, … Read more

get post id from wp_insert_post for get_template_part

Declare $my_post_id as global in your code. Declare $my_post_id as global in the-post.php template. Your code: global $my_post_id; $my_post = array( ‘post_type’ => ‘theposttt’, ‘post_title’ => ‘test’, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => 1 ); $my_post_id = wp_insert_post($my_post); if(is_wp_error($my_post_id)) $my_post_id = 0; Now, you can use $my_post_id in the-post.php template. Possible values: 0 … Read more

processing form data with ajax

This way to insert data in db using AJAX works for me. Hope this help you. Function scripts function add_our_script() { wp_register_script( ‘ajax-js’, get_template_directory_uri() . ‘/scripts/keeled.js’, array( ‘jquery’ ), ”, true ); wp_localize_script( ‘ajax-js’, ‘ajax-js_ajax’, array( ‘ajax_url’ => admin_url( ‘admin-ajax.php’ ) ) ); } add_action( ‘wp_enqueue_scripts’, ‘add_our_script’ ); Template Form: <form> <label for=”nimi”>Nimi</label> <input name=”nimi” … Read more

How to Add Shortcode to html img code?

You cannot use Shortcodes in attributes since 4.2.3, for security reasons. See the announcement (emphasis mine): Earlier today, we released WordPress 4.2.3, which includes a relatively large security fix that affects the Shortcode API. Due to the nature of the fix – as is often the case with security fixes – we were unable to … Read more

How to translate wordpress error message

I was able to solve my problem, follow the code in case someone needs the solution: add_filter(‘login_errors’,’login_error_message’); function login_error_message($error){ //check if that’s the error you are looking for $pos = strpos($error, ‘incorrect’); if (is_int($pos)) { //its the right error so you can overwrite it $error = “Um ou mais campo estão em branco ou dados … Read more

Need to convert image url to a Base_64 data url with wordpress function..

In your post you wrote : “which will show an image like below”, I assume that your shortcode return an img tag and you have to find your URL here, tell me if I’m wrong. Using DOMDocument http://php.net/manual/fr/class.domdocument.php to parse your img tag is a good idea. $img = do_shortcode(‘[user_meta_avatar_pic]’); // Here your get your … Read more