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

Advice: Template structure – php blocks in sidebar or someting else?

I would say to add them as template parts as in content-[name].php. For instance in page.php you could have something like: <?php while ( have_posts() ) : the_post(); ?> <?php if (is_page( ‘home’ ) ){ get_template_part( ‘content’, ‘benefits’ ); } elseif (is_page( ‘Contact’ ) ){ get_template_part( ‘content’, ‘contact’ ); } } get_template_part( ‘content’, ‘popup’ ); … Read more

Editing or filtering the output of the Genesis navigation

You could try to use the wp_nav_menu_args filter (untested): /** * Add the Menu_With_Data_Attr walker to the wp_nav_menu() used by genesis_do_nav() */ add_filter( ‘wp_nav_menu_args’, function( $args ){ if( isset( $args[‘menu_class’] ) && ‘menu genesis-nav-menu menu-primary’ === $args[‘menu_class’] ) { if( class_exists( ‘Menu_With_Data_Attr’ ) ) { $args[‘walker’] = new Menu_With_Data_Attr(); } } return $args; }); to … Read more

Display height and width properties with the_post_thumbnail() or related function

You can collect image attributes using “wp_get_attachment_metadata“, see below example as starting point function mytheme_post_thumbnail( $size=”post-thumbnail”, $attr=””, $post_id = null ) { if ( has_post_thumbnail( $post_id ) ) { $meta = wp_get_attachment_metadata( get_post_thumbnail_id( $post_id ) ); $args[‘width’] = $meta[‘sizes’][$size][‘width’]; $args[‘height’] = $meta[‘sizes’][$size][‘height’]; $args[‘alt’] = isset( $attr[‘alt’] ) ? $attr[‘alt’] : apply_filters( ‘post_title’, get_post( $post_id )->post_title … Read more

Issue adding text after short description on product pages Woocommerce [closed]

The Correct syntax for writing a add_filter // Define the woocommerce_short_description callback function filter_woocommerce_short_description( $post_excerpt ) { // make filter magic happen here… return $post_excerpt; }; // add the filter add_filter( ‘woocommerce_short_description’,filter_woocommerce_short_description’,10, 1 ); Your code didn’t work well because the reason is that filter are used to modify the output. Here is the function … Read more

Theme options WP Editor

In theme options, I had to define wp_editor_settings. So, just in options.php, I used: //WP_editor settigs $wp_editor_settings = array( ‘wpautop’ => true, // Default ‘textarea_rows’ => 15, ‘tinymce’ => array( ‘plugins’ => ‘fullscreen,wordpress,wplink, textcolor’ )); Basically, I’m adding tinymce plugin.

WooCommerce add_action hook results in 500 error

Remove the = sign after your echo statement… echo = “<p>Text Goes Here</p>”; …becomes echo “<p>Text Goes Here</p>”; Final add_action( ‘woocommerce_review_order_after_shipping’, ‘action_woocommerce_review_order_after_shipping’); function action_woocommerce_review_order_after_shipping( ) { echo “<p>Text Goes Here</p>”; }