Need help with PHP functions

add_shortcode(‘show_name’, ‘generate_content’); When WordPress finds a [show_name] shortcode tag in content, it runs the function that matches the second parameter, which in this case is generate_content. Try renaming your show_name() function to be the same, like this: add_shortcode(‘show_name’, ‘my_show_name_func’); function my_show_name_func() { $current_user = wp_get_current_user(); $first_name = $current_user->user_firstname; return $first_name; } Everything else looks like … Read more

WooCommerce remove_action and add_action [closed]

You can create your own dedicated function and overwrite a default one when a function is in a function_exists statement. if ( ! function_exists( ‘woocommerce_template_single_add_to_cart’ ) ) {} You can use the woocommerce_template_single_add_to_cart function from wc-template-functions.php Just copy/paste this function to your woocommerce-functions.php and modify it with the statement you want. This method is simple … Read more

Singleton plugin activation; create database

There is an error here. You’ve not declared _register_hooks() method. And I instantiated the class like below- global $p; if(empty($p)){ $p = plugin::getInstance(); $p->activate(); } And it worked. For your case that has not worked cause WordPress uses a variable with name $plugin in its life cycle. And your code checks it’s empty or not. … Read more

Call get_template_part() custom permalink

Mapping of URL directly to a template file you describe (mapping URL to a file) is quite rare technique in WordPress, sometimes called static pages. It is rare because in general that’s not how WordPress works. It works by mapping URL to query variables to WP_Query to template hierarchy to template file. Going from URL … Read more

List categories assigned to a post

You can use get_the_category( ) instead. Example: $categories = get_the_category(); foreach( $categories as $category) { $name = $category->name; $category_link = get_category_link( $category->term_id ); echo “<a href=”https://wordpress.stackexchange.com/questions/249463/$category_link”> <span class=” . esc_attr( $name) . “></span> </a>”; }