Tag Info

Hot answers tagged

8

At the risk of getting voted down by everybody else here who thinks this is OK. I say: No, you shouldn't define functions in template files. This should be considered bad practice. Let's have a look at the documentation: Functions File Explained. The functions file behaves like a WordPress Plugin, adding features and functionality to a WordPress ...


2

You can use in this way <?php $sTitle = "Your, Title";// From get_the_title(); or other sources if(strpos($sTitle , ",")){ $sTitle = substr($sTitle , strpos($sTitle , ",") + 1); } echo $sTitle; // You can also trim($sTitle); to remove whitespaces left from substr() ?>


2

Sure. If your function is really just doing some control switching, putting it into the template is fine. Anything more than that traditionally goes into functions.php or similar. Edit: +10 at Pieter Goosen's mention of trying to keep things DRY. It can actually be difficult to keep things DRY with WordPress theming. I'm a fan of the Sage starter theme. ...


1

There is no wrong or right way, neither is there any type of set rule or standard stating where custom code should go or not. This is all personal preference. There are few guidelines which you should use (if you want to) Templates (and all code for that matter) should be kept organised, maintainable, and easy to read and understand. Do not clot code ...


1

You have a couple of flaws here: ALWAYS code in a way with a mindset of that your code will fail. This is very important. Most people code with a perfect world mindset. A perfect world will never happen. Always think of what will happen when your code fail. As example, in your code, $terms return an object of term objects if everything pans out. $terms ...


1

You just need to echo it. <?php echo $price - $trade; echo $trade / $sale; ?> or you can go more advanced by going <?php if ( ! is_admin() ) { // is admin then echo $price - $trade; echo $trade / $sale; } else { // is not admin then } ?>


1

If you dont want 'TopLevel' menu to represent a custom page you can use: add_menu_page( 'TopLevel', 'TopLevel', 'MENU_CAP_LVL', 'MENU_SLUG', 'MENU_CB' ); add_submenu_page( 'MENU_SLUG', 'SubMenu', 'SubMenu', 'MENU_CAP_LVL', 'SUB_MENU_SLUG', 'SUB_MENU_CB' ); add_submenu_page( 'MENU_SLUG', 'SubMenu-A', 'SubMenu-A', 'MENU_CAP_LVL', 'SUB_MENU_A_SLUG', ...


1

You can use WP_Query to get almost any post data out of your Wordpress install. $sub_pages = new WP_Query( array( 'post_parent' => 3, 'post_type' => 'page' ) ); print_r($sub_pages->posts); This would get you the following: Array ( [0] => WP_Post Object ( [ID] => 94 [post_author] ...


1

Place your file in the same directory as the template. On the single.php and page.php files you'll want to include: <?php include('your_file.php'); ?>


1

Try changing your code to: <?php echo do_shortcode('[ai1ec tag_name="' . $calendar . '"]'); ?>


1

$count is just an arbitrary variable name. If you're using a separate loop to get tags and stop after a certain number (as shown on https://codex.wordpress.org/Function_Reference/get_the_tags), replace the $count variable in that example code with something like $tag_count or $counting or $treebark, and it won't mess up your use of $count in the posts Loop ...


1

You need to pass author__in as an array but that isn't what you doing with this: ( array( 'author__in' => array( $followed ) ) ). You are creating an odd set of nested arrays. WP_Query isn't going to know what to do with it. A much simplified version should work: $followed = $wpdb->get_col(" SELECT user_id1 FROM wp_um_followers WHERE user_id2 ...


1

change this line: $item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after; to: $item_output .= $args->link_before . apply_filters('the_title', substr($item->title, 0, 10), $item->ID) . $args->link_after; That limits the character to 10. Please note this substr($item->title, ...



Only top voted, non community-wiki answers of a minimum length are eligible