Can is_page() be combined with a switch control structure?

While Ben’s answer is basically correct, is_page also checks to make sure that the query is indeed a Page and not something else with the same post_name. So to be 100% accurate, you could do something like this: if ( is_page() ) { // only do this for actual pages $page_obj = get_queried_object(); switch ( … Read more

Add relevant tag to search results

In functions.php: function wpse82525_link_search_to_tag() { // check if search archive is being displayed if( ! is_search() ) return; // get search query var $sqv = get_query_var( ‘s’ ); // get tag base $tagbase = get_option( ‘permalink_structure’ ) ? get_option( ‘tag_base’ ) ? trailingslashit( get_option( ‘tag_base’ ) ) : ‘tag/’ : ‘?tag=’; // return link if … Read more

How to access function from outside of a class within this class in WP plugin?

Create a static getter for your class instance: class DD_Awesome_Plugin { /** * Plugin main instance. * * @type object */ protected static $instance = NULL; /** * Access plugin instance. You can create further instances by calling * the constructor directly. * * @wp-hook wp_loaded * @return object T5_Spam_Block */ public static function get_instance() … Read more

conditional statement for custom taxonomy

I’m pretty sure you shouldn’t use negation in your conditions… If you check ! is_tax… it will be true not only for other taxonomy pages, but also for singular pages, and any other… So it should look like this: <?php if ( is_tax(‘taxonomy-name’,’taxonomy-one’ ) ) {?> <div class=”test” style=”color: red”><?php the_field(‘field_name’); ?></div> <?php } elseif … Read more

items_wrap not working

your problem is in your use ‘menu_class’ and ‘items_wrap’ not synchronized. You can edit : wp_nav_menu( array( ‘theme_location’ => ‘header-menu’, ‘container’ => ”, ‘echo’ => ‘0’, ‘menu_class’ => ‘nav-menu horiz-menu container sixteen columns’, ‘items_wrap’ => ‘<ul class=”%2$s”>%3$s</ul>’ ) ) or: wp_nav_menu( array( ‘theme_location’ => ‘header-menu’, ‘container’ => ”, ‘echo’ => ‘0’, ‘items_wrap’ => ‘<ul class=”nav-menu … Read more

Can I use `.phtml` instead of `.php`

I’m going to echo all of the above comments & say it’s not a good practice to get into. You might want to borrow a convention from the PHPTemplate library used in Drupal and call your files something.tpl.php. That way it’s still a .php file, but you have an extra extension showing it’s a template.

Different database query in function.php using mysqli

Since version 3.9 (that will be released soon, actually in beta 2) WordPress will use mysqli to connect to database (3.9- versions use mysql) so you can actually use new wpdb instances and helper function to connect externa values from WordPress. What I suggest is to configure external database using constants in wp-config.php in this … Read more

Add WordPress to Meteor js site

This question is probably beyond the scope of WPSE. But my solution would be to install PHP-FPM and run Node and PHP-FPM on different ports behind Nginx. Sample Nginx Config (will require tweaking) location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://localhost:3000; // Assuming Node is running … Read more

Making Quote Plugin more efficient

Is there more efficient ways to validate the quotes using the WordPress api? I think you should set a nonce for the form You also should check if current user has capability to save quote To get properly sanitize values form $_POST look at filter_input and/or filter_input_array I don’t see performance issues on validation, but … Read more