How to break up php code to avoid echo

You have an extra “}”, there must be two such braces for two for each loops. Also you need to have endif; statement at end after endwhile. Parsing error may be due to extra “}”. Please try below code and let us know if it works. <?php $custom_terms = get_terms(‘videoscategory’); $other_custom_terms = get_terms(‘product_category’); foreach ($custom_terms … Read more

Add “alt” Attribute to GD Star Rating Tags

Add the attribute to each line of code that creates an img tag. In your text editor, search for lines that contain the string “<img”. Lines 241 and 273: $row->item_trend_rating = sprintf(‘<img class=”trend” src=”https://wordpress.stackexchange.com/questions/96226/%s” style=”https://wordpress.stackexchange.com/questions/96226/%s” width=”https://wordpress.stackexchange.com/questions/96226/%s” height=”https://wordpress.stackexchange.com/questions/96226/%s”></img>’, $gdsr->e, $image_bg, $set_rating->size, $set_rating->size); Becomes: $row->item_trend_rating = sprintf(‘<img class=”trend” src=”https://wordpress.stackexchange.com/questions/96226/%s” style=”https://wordpress.stackexchange.com/questions/96226/%s” width=”https://wordpress.stackexchange.com/questions/96226/%s” height=”https://wordpress.stackexchange.com/questions/96226/%s” alt=”https://wordpress.stackexchange.com/questions/96226/%s”></img>’, $gdsr->e, $image_bg, $set_rating->size, $set_rating->size, … Read more

Wp favorites posts by specific category? [closed]

This should do what you want: $have_favorite_posts = false; $favorite_post_ids = wpfp_get_users_favorites(); $cat = get_category_by_slug(‘news’)->cat_ID; // or if you want to use the category name (as tried in your code) // $cat = get_cat_ID(‘News’); if (! empty($favorite_post_ids)) { $fp_query = new WP_Query(array( ‘cat’ => $cat, ‘post__in’ => $favorite_post_ids, )); if ($fp_query->have_posts()) { $have_favorite_posts = true; … Read more

Display random image url from list of input values

Instead of echoing out these images, just store them as strings inside an array and choose one of the array items at random. <?php $headerimage_options = get_option(‘headerimage_options’ ); $images = array(); $images[] = ‘<img title=”‘.get_bloginfo(‘name’).'” src=”‘.esc_url( $headerimage_options[‘image’] ).'”/>’; $images[] = ‘<img title=”‘.get_bloginfo(‘name’).'” src=”‘.esc_url( $headerimage_options[‘image2′] ).'”/>’; $images[] = ‘<img title=”‘.get_bloginfo(‘name’).'” src=”‘.esc_url( $headerimage_options[‘image3′] ).'”/>’; $v = array_rand($images); … Read more

Display message depending on capability outside loop

Use global $authordata: Testing for roles: global $authordata; if ( in_array( ‘administrator’, $authordata->roles ) ) { echo ‘Hello Admin!’; } elseif ( in_array( ‘editor’, $authordata->roles ) ) { // echo something else } Or testing for capabilities: if ( ! empty ( $authordata->allcaps[‘manage_options’] ) ) { echo ‘The author can manage options’; } elseif ( … Read more

Add a select-option to the default widgets

The default widgets do not offer any hooks for that. You have to replace the default widget and add your field to the new class. The other option would be using JavaScript to insert the field, and a filter for ‘update_option_widget_’ . $widget->id_base to save the value. I think the separate class is the cleaner … Read more

How to display only one category in a custom post type?

Something like this should work but you haven’t stated where you want to display the CPT pages for games. function display_games_archive( $query ) { if ( !is_admin() || $query->is_main_query() && is_post_type_archive( ‘portcat’ ) ) { $query->set( ‘category__in’, ‘games’ ); return; } } add_action( ‘pre_get_posts’, ‘display_games_archive’, 1 );

Strip from or something better?

Manipulating HTML with regular expressions is not a good idea. I suggest you use DOMDocument: // input $html = apply_filters(‘the_content’, get_the_content()); $dom = new \DomDocument(); $dom->loadHtml($html); $blockquotes = $dom->getElementsByTagName(‘blockquote’); foreach($blockquotes as $blockquote){ foreach($blockquote->childNodes as $e){ if($e->nodeName === ‘p’){ // create a text node with the contents of the <p> $blockquote->insertBefore($dom->createTextNode($e->textContent), $e); // remove <p> $blockquote->removeChild($e); … Read more

Get value from db for custom contact form

Add this at the start of your process.php file to get access to get_option and other wordpress functions: define( ‘WP_USE_THEMES’, false ); require(‘wp-blog-header.php’); You might have to change the path to wp-blog-header.php.