Shortcode don’t work in custom option field, any solution?

If you have a shortcode string saved, try echoing it with do_shortcode function, which turns shortcodes into content. $saved_shortcode = get_option( ‘my_customizer’, ‘copyright’ ); if ( $saved_shortcode && is_string( $saved_shortcode ) ) { echo do_shortcode( $saved_shortcode ); } More about the function on the developer handbook, https://developer.wordpress.org/reference/functions/do_shortcode/ EDIT Another option is just echo the year … Read more

Woocommerce checkout field

Try : add_filter( ‘woocommerce_checkout_fields’ , ‘custom_override_checkout_fields’ ); function custom_override_checkout_fields( $fields ) { if(is_user_logged_in()){ unset($fields[‘billing’][‘billing_email’]); } return $fields; } Source : https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

Regenerating WordPress shortcodes based on value with AJAX

In order to change the shortcode value by leveraging ajax, you need to modify the PHP code and jQuery as mentioned below: function table_generator() { // Set product providers $providers = array( ‘Provider 1’, ‘Provider 2’, ‘Provider 3’, ); // Build provider selection form $output .= ‘<form id=”submitProvider” action=”” method=”POST”>’; $output .= ‘<select name=”provider_list”>’; $output … Read more

get_posts() from parent category only using a shortcode

If you don’t want to include posts in child categories, use the category__in parameter: $args = array( ‘category__in’ => [ get_cat_ID( $category_name ) ], // use category__in //’category_name’ => $category_name, // and not this. ‘post_type’ => ‘menu’, ‘numberposts’ => -1, ‘post_status’ => ‘publish’ ); And although the above would give you what you wanted, the … Read more

Do I need to escape number in this shortcode function?

Yes, never trust user’s input. Just because you told people to provide a valid number for a specific shortcode parameter, it doesn’t guarantee that the input will always be a valid number, so always secure user’s input — and output. You should also, if you haven’t already done so, read these articles: Data Validation Securing … Read more

Shortcode conflicts

When you define your shortcode, you might try one of a couple “if” statements to fix this issue, until you have time to create separate shortcodes. function cfgeo_shortcode( $atts, $content = “” ) { if (!isset($content) || stristr($content,’cfgeo’)!==FALSE){ // do short shortcode stuff here } else { // do ‘Container’ shortcode stuff here } return … Read more

Implementing a URL Shortener

Step 1: Create a new template file in your themes folder named: shorturl.php <?php /* Template Name: Short URLS Template Post Type: post, page */ while ( have_posts() ) : the_post(); $content=get_the_content(); header(‘Location: ‘.str_replace(“&amp;”,”&”,$content)); exit(); endwhile; Step 2: Create a new php file in your wp-content/plugins/ folder and name it: public-url-shortener.php <?php /* Plugin Name: … Read more