Custom Meta Field – Youtube embed

Maybe it’s better to use a textarea instead of an input field. And of course $allowed doesn’t contain the iframe tag. And for sure you will be not able delete the saved video_1… Too many things not really good in this code. 1) $values = get_post_custom( $post->ID ); $video1 = isset( $values[‘video_1’] ) ? esc_attr( … Read more

Displaying a variable stored in functions.php inside widget

The widget operates in a different scope than the functions.php. You could use two different approaches to get around that. Make the variable global (put it into the top scope): // functions.php $GLOBALS[‘var_name’] = ‘hello’; // widget echo $GLOBALS[‘var_name’]; But that is risky: any other script can change the variable now accidentally, and it is … Read more

How to have a custom display for both woocommerce archive and product-category pages? [closed]

Generally, you can tell WordPress to load a different template. The mostly seen approaches make either use of the template_redirect or the template_include hook. It is preferable to use template_include as described in this article. Following an example on how to approach this: Code: // load the woocommerce category archive template add_filter( ‘template_include’, ‘wpse138858_woocommerce_category_archive_template’ ); … Read more

Calculate percentage of post by category

With a little CSS, this will create a list of categories like so: Basic CSS: <style> .bar { height:4px; background:blue; } </style> The PHP: <?php // To customize visit http://codex.wordpress.org/Function_Reference/get_categories $categories = get_categories(); // Get total posts, this allows for posts to have more than one category and accommodates for custom $args in get_categories($args) $total_posts … Read more

How to disable wordpress confirmation email for new users

I noticed the current answers are plugin based only. You can use wpmu_signup_user_notification to achieve this without installing a plugin. Add to your functions.php – this will disable user signup notifcations completely. add_filter( ‘wpmu_signup_user_notification’, ‘__return_false’ ); You can read more wpmu_signup_user_notification here: https://developer.wordpress.org/reference/functions/wpmu_signup_user_notification/

Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’

Luckily, I was facing the same issue an hour ago so I brainstormed for a long time to find a find a solution. I posted it here before seeing this: http://www.hardeepasrani.com/2015/12/using-postmessage-transport-method-for-header-image/ So instead of just using: $wp_customize->get_setting( ‘header_image’ )->transport=”postMessage”; I used: $wp_customize->get_setting( ‘header_image’ )->transport=”postMessage”; $wp_customize->get_setting( ‘header_image_data’ )->transport=”postMessage”; After that, in JS, we got the value … Read more

Current post’s author name in the author meta tag

You cad add it via functions.php with a hook, instead of inside the loop (you don’t really want to add a loop to header.php): function add_author_meta() { if (is_single()){ global $post; $author = get_the_author_meta(‘user_nicename’, $post->post_author); echo “<meta name=\”author\” content=\”$author\”>”; } } add_action( ‘wp_enqueue_scripts’, ‘add_author_meta’ );

WordPress Shortcode and Dynamic CSS

The closest to a reference technique in core would be shortcode. If you look at the source of implementing gallery_shortcode() function you’ll see that it: Generates instance number (so multiple shortcodes can be distinguished). Outputs dynamic CSS inline into a page source, for each instance. I wouldn’t consider it particularly neat solution, but it is … Read more