If in category to be inside of a function

If you want to use the function to output the code somewhere: function displayImage($currentPost) { // Show the featured icon only if current post is in “featured” category if ( in_category ( ‘featured’, $currentPost ) ) { $output=”<a href=”https://wordpress.stackexchange.com/questions/58811/<?php the_permalink(); ?>”> <span class=”featured_icon”> <img src=”<?php bloginfo(“template_directory’); ?>/images/featured_icon.png” /> </span> </a>’; } else { $output=”” }; … Read more

Get the 5 lastest Featured Posts from a category

<?php /* Set the name of the category and the number os posts to be displayed */?> <?php $first_query = new WP_Query(‘category_name=name&posts_per_page=7’); ?> <?php /* Show the posts */ ?> <?php while ($first_query->have_posts()) : $first_query->the_post(); ?> <?php /* Make the hiperlink to the post */ ?> <a href=”https://wordpress.stackexchange.com/questions/59934/<?php the_permalink(); ?>”> <?php /* Get the featured … Read more

edit role display name and label name without plugins

Those names are stored in the option wp_user_roles in the database table wp_options. So, the following will change the name of the subscriber role: $val = get_option( ‘wp_user_roles’ ); $val[‘subscriber’][‘name’] = ‘PeDeBoi’; update_option( ‘wp_user_roles’, $val ); Apparently, this is harmless, but caveat emptor… In your code, $wp_roles->roles[$role][‘name’] = $new_role_name; doesn’t work because it should be: … Read more

Add a Second Menu to a theme that only support 1 menu

Adding custom menu position to your wordpress theme is fairly simple. This is usually done this way: 1. Announcing the desired menu positions (in function.php): add_action( ‘init’, ‘register_my_menus’ ); function register_my_menus() { register_nav_menus( array( ‘first-menu’ => __( ‘First Menu’ ), ‘second-menu’ => __( ‘Second Menu’ ), ‘third-menu’ => __( ‘Third Menu’ ) ) ); } … Read more

Avoiding Duplicate function names in Post Loop (WP_Footer script)

I would wrap the whole thing in a class and put your data into a class var. class WPA69616_Plugin { private $data=””; public function __construct() { add_shortcode(‘my_shortcode’, array($this, ‘add_content’)); add_action(‘wp_footer’, array($this, ‘output_content’)); } public function add_content($atts) { extract( shortcode_atts( array( ‘content’ => ” ), $atts ) ); $this->data .= $content; } public function output_content() { … Read more

Change Rating range in Link Manager

See the function link_advanced_meta_box() in wp-admin/includes/meta-boxes.php: <td><select name=”link_rating” id=”link_rating” size=”1″> <?php for ( $r = 0; $r <= 10; $r++ ) { echo ‘<option value=”‘ . $r . ‘”‘; if ( isset($link->link_rating) && $link->link_rating == $r ) echo ‘ selected=”selected”‘; echo(‘>’ . $r . ‘</option>’); } ?></select>&nbsp;<?php _e(‘(Leave at 0 for no rating.)’) ?> The … Read more

Defining a global array in functions.php?

In order to access a variable defined in the global scope you must reference it with the global keyword wherever you want to call it again. In your case, the function create_year_terms() must call the global $year_arr within its scope. Also, you can always get your variable in the global scope by using the $GLOBALS … Read more