Multisite Conditional (if blog_id?) in a page template?

I have a WordPress network with multiple sites using the same theme. Now I need to edit part of a certain PageTemplate.php to display different things based on the blog id. Example: If blog ID 1, run this: <a href=”https://wordpress.stackexchange.com/questions/124104/<?php if(get_post_meta($post->ID,”videoembed_videopopup’, true)): ?><?php echo get_post_meta($post->ID, ‘videoembed_videopopup’, true) ?> <?php else: ?> <?php if(get_post_meta($post->ID, ‘links_link_custom’, true)): … Read more

Display several random posts, but make sure a condition is met

I have a custom post type for a group of people (employees). At first, I needed to display 7 random employees. That was easy <?php $args = array( ‘post_type’ => ’employees’, ‘orderby’ => ‘rand’, ‘posts_per_page’ => 7, ); $query = new WP_Query($args); while ( $query->have_posts() ) { $query->the_post(); //do stuff <?php endif; } wp_reset_postdata(); ?> … Read more

Check if first paragraph is an image, then show custom code right after it?

I would like to add some code in functions.php that does this: If the first paragraph contains an image, show my custom code right AFTER it. For example: <div class=”entry-content”> <p><img src=”http://example.com/example.jpg” alt=”Image in 1st para” /></p> <div>MY CUSTOM CODE</div> </div> But if the first paragraph is text (i.e. NOT an image), show my custom … Read more

Display navigation menu item conditionally based on user capabilities

I have one “branch” of my main site’s navigation tree that should only be accessible to a set of registered, logged-in users. I understand how to query a user’s role and capabilities. This question is specifically about what is the best way to leverage the build-in nav menu, but just hide an item conditionally. Do … Read more

wp_enqueue_script adding conditional statement not working

This is the code im using in my functions file: add_action(‘init’, ‘sort_out_jquery_pngfix_frontend’); function sort_out_jquery_pngfix_frontend() { global $wp_scripts; if(!is_admin()) { wp_deregister_script(‘jquery’); wp_register_script(‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js’, array(), NULL, true); wp_register_script(‘dd_belatedpng’, get_stylesheet_directory_uri() . ‘/js/dd_belatedpng.js’, array(), NULL, true); $wp_scripts->add_data(‘dd_belatedpng’, ‘conditional’, ‘lt IE 7’); } } add_action(‘wp_print_scripts’, ‘register_theme_scripts’); function register_theme_scripts() { if(!is_admin()) { wp_enqueue_script(‘modernizr’, get_stylesheet_directory_uri() . ‘/js/modernizr-1.7.min.js’, array(), NULL, false); wp_enqueue_script(‘googlemaps’, ‘http://maps.google.com/maps/api/js?sensor=false’, … Read more

how to create a conditional content_width for a wordpress theme?

I’m trying to create a conditional statement for the content width in the functions.php of my theme. So some categories will have a content_width of 580, some will have 900. This will make the oEmbed work correctly wherever it’s used. Usually, you would have this in your functions.php: if ( ! isset( $content_width ) ) … Read more

How to conditionally enqueue a stylesheet only for a certain page(s)?

Before I get started, I want to acknowledge that there are some really good articles that are targeted at how to conditionally enqueue scripts based on page/post content. WordPress Plugin Development – How To Include CSS and JavaScript Conditionally And Only When Needed By The Posts How to load JavaScript like a WordPress Master These … Read more