INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
How to unset adminmenu completely? Is there a way to completely remove (unset) the left hand side admin menu? I examined the ozh-admin-drop-down-menu plugin, since it removes the entire admin menu and adds a top menu bar in order to get a clue.. I made a few snippets, but probably I am missing sth.. I couldn't manage to find a way out..
Just to explain the solution better: I made below additions to theme's function.php in order to remove visually (hide) left hand admin menu: add_action('admin_init', 'add_custom_admin_style'); function add_custom_admin_style(){ wp_register_style('custom_admin_style', content_url('themes').'/custom_admin.css'); wp_enqueue_style('custom_admin_style'); } And then I created custom_admin.css file in themes folder and put below lines: #adminmenuwrap, #adminmenuback {display:none;} #wpcontent, #footer {margin-left: 15px;}
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "admin menu" }
Images will not attach to posts after site migration I recently migrated a WordPress install from a subdirectory to the root. After the migration everything worked great, except that I can no longer set a featured thumbnail or add a picture in the WYSIWYG. On a possibly related note, I can only set post tags from the Quick Edit screen and not the post edit screen. When I click set featured image on the post edit screen it opens the screen to add media, but it opens in a new page, not like in a box before. When I click to the media library and click show next to an image, it does not show and so I can't select "use as featured image." I can still upload the photo, but I can't attach it to the post. I'm not sure if the tags issue is related, but whenever I enter a tag in the Post Tag box it will not save. But if I go out to the All Posts listing, I can enter them via Quick Edit. Any ideas? Thanks in advance.
I figured it out. It was a jQuery conflict. I deregistered the default jQuery in WordPress to use the Google CDN version. Works great on the front-end, but it was messing up the admin. Wrapped it in an !is_admin() if statement and all is well.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, post thumbnails, migration" }
the_post_thumbnail hard cropping not working no matter what No matter what I do - I can't get the hard cropping mode in the_post_thumbnail to work. Here's what I have: add_image_size( 'Blog', 300, 300, true ); the_post_thumbnail('Blog'); I've also tried: set_post_thumbnail_size( 300, 300, true ); the_post_thumbnail(); I've tried uploading new images, and using the "Regenerate Thumbnails" plugin, but still no luck. It completely ignores the "true", and acts as if it's "false". For example, instead of the image being 300x300, it'll be 300x238 or something. Has anyone else experienced this? My GD Library is enabled.. Thanks for any input anyone can offer =)
I've actually finally fixed this issue. It seems that the hard-cropping works if you set the image size inside a function that is hooked into the "after_setup_theme" hook. So, the below would work: function add_custom_sizes() { add_image_size( 'portfolio-thumb', 243, 163, true ); add_image_size( 'portfolio-image', 1074, 725, true ); add_image_size( 'available-homes', 500, 279, true ); add_image_size( 'idea-thumb', 146, 141, true ); } add_action('after_setup_theme','add_custom_sizes'); This will allow you to get actual hard cropped images using the sizes specified using the_post_thumbnail(). Hope this helps someone else as well.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 8, "tags": "post thumbnails" }
extract shortcodes from string i need a little help to with this issue: I have a string wich contains shortcodes like `[shortcode data="1" data2="2"]` How I can extract with regex? without wordpress system? Thanks in advance.
Where is this string located ? I know you wrote "without wordpress system" , but WordPress has a function get shortcode regex If you really want to avoid it for some reason, the following example might help you : // check the post for a short code function check_shortcode( $shortcode = NULL ) { $post_to_check = get_post( get_the_ID() ); // Until we search, set false $found = false; // no short - FALSE if ( ! $shortcode ) { return $found; } // check the post content for the short code if ( stripos( $post_to_check->post_content, '[' . $shortcode) !== FALSE ) { // we have found the short code $found = TRUE; } // return our final results return $found; }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "regex, shortcode" }
how to change displaying order of products in wp ecommerce I am working on a wp-ecommerce enabled site and am trying to change the display order of the products on the product grid page. Any help would be greatly appreciated.
In the WordPress backend select **Settings** | **Store** . Select the **Presentation** tab. Scroll down to the **Product Page Settings** section and change the value of the **Sort Product By** dropdown to: **_Drag & Drop_** Now you are able to click on a product in **Products | Products** , hold it and drag it to the position in which you want it to appear.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "e commerce" }
Wordpress: embedding last posted video I need to embed the last posted video (from a specific category) to the frontpage of my Wordpress site. Is there any shortcode (or widget, even) I can use to simply filter my posts by category, and have the content (in this case, an embedded .wmv or .m4v) displayed based on a "last posted" basis. I am currently able to get a simple static embed working, but I need the embed to be dynamic based on the last video posted. The video cannot be hosted on sites like youtube or vimeo; I need to have them hosted as video files on a server and embed them that way. Thanks in advance.
This should work, even outside of the loop: $latestPost = get_posts('numberposts=1&category=YOUR_CATEGORY_ID'); The Wordpress function `get_posts` sorts by post date, newest-to-oldest by default, so you'd get the newest post in whatever category you choose. Also, even though you are only requesting one post, the response will still be an array: echo $latestPost[0]->post_content; **Edit:** Since the video embed code is being provided by a plugin that uses a shortcode, you'll have to use the function `do_shortcode` on the content. If there is text (content _other_ than the video) you'll have to parse out the shortcode from the `post_content`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "embed" }
How to make search include data from wp_postmeta? I have a site using Advanced Custom Fields to create and store various bits of relevant info. These need to be included in the main general search, which by default only searches the title and main content. I've found plenty of info about getting search results based on specific bits of postmeta, but I have an issue with that. There are a potentially unlimited amount of potential fields in postmeta to search. The solution could either search anything in postmeta or anything with a meta_key that matches this regex: `content_section_[0-9]{1,4}_content_.{2,8}` Example meta_keys to match are: content_section_0_content_title content_section_0_content_title content_section_4_content_subtitle content_section_8_content_text Any way that I can alter the fields searched to include the postmeta would be very much appreciated.
If your up for using a plugin, Relevanssi - A Better Search might be worth trying out. The standard (free) version supports searching post meta.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 14, "tags": "search, post meta, regex" }
All font sizes change when manually typing 2011 into url and going to archive page I am developing a site on MAMP and everything is going fine except that I thought I would check how all the default archive pages look. I typed 2011 at the end of the base url and it retrieved a yearly archive as expected. The problem is that the font sizes of every element change to a smaller size. I understand that there are different headings in the archives, but this problem affects the main nave menu, normal li items ... everything. Has anyone had this happen to them? Thank you.
Use your browser’s debugger to find the applied CSS rules. Usually there are some some unclosed elements and/or some badly written CSS rules like `#content * { font-size: .9em }`. It’s not a WordPress problem. :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "urls, archives" }
Showing Notifications While Activating Plugin I want to give errors like this, while activating my plugin. !enter image description here Which hooks should i use ? Can you share simple examples ? In shortly,when user activate my plugin, is a directory's CHMOD isn't 777 , i'll warn it and stop activation.
Check out : WP Error And this link covers how the plugin activation error works: < And I don't see any reason why you should ever chmod a directory to 777
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugins, plugin development, hooks" }
A little confused as to what add image size actually does I have a call to add_image_size like so: if ( function_exists( 'add_theme_support' ) ) { add_theme_support( 'post-thumbnails' ); } if ( function_exists( 'add_image_size' ) ) { add_image_size( 'sidebar_thumb', 109, 60 ); } But then when I try to use that image size in my template... if ( has_post_thumbnail() ) { the_post_thumbnail( 'sidebar_thumb' ); } The first image is 80X60, the second is 45 X 60; that's obviously way off. !images are not the size I wanted =The height is right on both images. So I guess my question is how do I get an image outputted with an exact size, and if that's not possible by default, then how would I get the URL of a featured image (the image than the user picked as Featured in the admin section) so I can put that URL into a script like timthumb.
Your not specifying a $crop value so your images are being cropped using a soft proportional crop. Set crop to TRUE for a hard crop. add_image_size( 'sidebar_thumb', 46, 60, TRUE); *no need to call function_exists for add_theme_support or add_image_size unless you want to be backwards compatible to pre 2.9.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "images" }
How to make classes for posts? Thanks in advance. I'd like to have posts with different colored borders and headers. It would be nice to choose a category of the post (red, blue, black, etc.) and have it change the class for that specific post. If it were outside of dreamweaver, it would use classes. So I could say: <div class="red box"> <h3>Header</h3> Content </div> Ideally this would work by having an option in the design view named 'classes' or 'post styles'. I would choose 'box' and 'red', and the style would be changed. Is this possible?
Use 'post_class' for custom CSS per post. An example with 3 variations (only use 1): <div id="post-<?php the_ID(); ?>" class="red box" ?>> //idea 1 <div id="post-<?php the_ID(); ?>" <?php post_class('box-color'); ?>> //idea 2 <div id="box-color" <?php post_class(); ?>> //idea 3 <h3>Header</h3> Content </div> To be able to choose a color in the post, use a custom field conditional. < To just change it based on category and such wrap the post class examples above in a category conditional. < The logic ( not proper code but ya): if in_category( array( 1,2,3 ) ) { // add your custom post class div }else{ // use default post class style.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, customization, css, post class" }
Remove Javascript generated by Comments In a theme I am working on, the comments form (mostly sure they are both comments form) adds javascript to the header. <script type='text/javascript' src=' <script type='text/javascript' src=' When I disable javascript I can still add comments and the comment form still works. So I wish to remove these from my header. I cannot find any documentation on how to do so, so **How can I remove these?**
You could remove scripts in the following manner. function custom_remove_scripts() { wp_dequeue_script('comment-reply'); } add_action( 'wp_enqueue_scripts', 'custom_remove_scripts' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "comments, javascript" }
Looking for Functions File that doesn't Exist My WordPress site seems to be running fine, except that trying to go to the plugins page gives the following error: Fatal error: Cannot redeclare _verifyactivate_widgets() (previously declared in .../public_html/wp-content/themes/news-child/functions.php:75) in .../public_html/wp-content/themes/news/functions.php on line 452 Deleting the theme so that WP reverts to the orignal does not help, it keeps trying to go to that functions.php. I cannot deactivate the plugins either (since the page is inaccessible). Ideas on what the cause/fix is?
As the error says you cannot redeclare a function. You need to open your child theme's functions.php and remove the `_verifyactivate_widgets()` function from it. If you have copied the functions.php from the parent theme then most probably you would have to remove all the functions from the file unless any function in the parent theme is declared like `if ( function_exists('_verifyactivate_widgets') )`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, errors, child theme" }
One WordPress and database but multiple subdomains I want to create a multiple subdomains, but using only one wordpress and database installation. The difference of those subdomain sites are the colors and the blogs, but in terms of functionalities, layout, plugins, they are just the same. Is this possible, or can I only go with the ratio 1 is to 1 (1 wordpress for 1 subdomain)?
you can achieve that in many ways, maybe the most suitable for you is to use the multisite function in WordPress 3.0 Read more at WordPress.org : * Create a Newtwork * Migrating Multiple Blogs into WordPress 3.0 Multisite
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "css, installation, subdomains" }
Locally change the font family I'm using the standard Wordpress theme ( _WordPress Default 1.6_ by Michael Heilemann). The standard font for my articles is a sans-serif font. I'd like to display, for a sentence only, a serif font ( _Times_ for instance). I didn't find a way to do this. Is it possible ?
This is not really a WordPress question but I'll answer it anyway. The first thing you need to know is CSS is your friend. You'll want to do something like this: In style.css `.serif-class {font-family: "Times", "Times New Roman", serif;}` Then using the html view inside of your post: `<span class="serif-class"> This is an important sentence </span>` See more on Span Here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, html, css" }
Using WordPress as a Framework I'm quite familiar with WordPress, but have just minimal experience with PHP frameworks such as Codeigniter. When building a custom application, say for example an invoicing system or time management app for my company, does it make sense to use WordPress as a framework, or would it be more advisable to use something like Codeigniter? What are the main differences in these two approaches?
Most frameworks are specifically designed to easily handle a large range of applications, while WordPress is quite limited when it comes to using its API to create applications like the one you mentioned. If you want to compare WordPress as a PHP framework with existing popular frameworks, think of it as one of the worst options. It's not that you can't implement certain functionality in WordPress, it's just that you will do it by writing more and less maintanable code than in Yii, Cakephp, codeigniter etc. My suggestion is to use whatever you feel more comfortable with. If you're willing to spend time learning to work with Codeigniter, go with Codeigniter, but if don't have that time you should probably stick to WordPress.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "framework" }
working with result of wp_dropdown_pages() With `wp_dropdown_pages();` it's able to make a dropdown list with the pages of the blog. How can I work with this function? I want to get a specific custom field of the "dropdown-selected page". Don't know the way so solve this problem.
Not sure what your trying to do with the custom field but you can create your own drop down select using the `get_pages()` function which returns an array of pages similar to the `get_posts()` function. $pages = get_pages(); foreach( $pages as $page ) { echo get_post_meta( $page->ID, 'your_meta_key', true ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "dropdown" }
Wordpress AJAX - how to return true or false in the callback function So I've set up AJAX with Wordpress properly, having followed some good tutorials, and it's working great. One thing I can't quite work out is how to properly return either TRUE or FALSE from within the callback function. My php function is as follows: function my_callback() { if(something()) { echo 'false'; } else { echo 'true'; } exit; } In the JS do I simply do `if(response == 'true') { // do something }` or is there a better way? This might seem a little trivial but this is the first time I'm really using AJAX!
this would work to: function my_callback() { if(something()) { echo 1; } exit; //no text sent or even exit('0'); will work } and in js: var response = do_ajax(); if(response){ //do stuff }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "ajax" }
Functions containing parameter 'yourtheme' I had a colleague create a new theme and while doing so he copied an old theme and made the changes necessary. Now, in many of the files, there are functions that contain the old theme name in the function call instead of the new theme name. Is this parameter used in WordPress for anything and I should therefore change it, or is it OK to leave it with the old theme name?
You can leave it or change it, it doesn't matter as long as the theme files use the correct handle for the function. I would choose one name and convert the second version so all use the same name to keep it simple.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "themes, wp admin, theme options" }
Wrap all post images inside a div element I searched for all kind of solution but i really could find one that did what i was looking for, what i simple want done is wrapping all images inside a div element, old post aswell as new posts. All help is very much appreciated p.s. I did a little jquery snippet but I really would like another solution the jquery code <script> $(function(){ $('a:has(img.postthumbimage)').wrap('<div class="myphoto" />'); }); </script>
Try using PHP's regular expression find/replace function—`preg_replace()`—in a filter on the `the_content` hook. function breezer_addDivToImage( $content ) { // A regular expression of what to look for. $pattern = '/(<img([^>]*)>)/i'; // What to replace it with. $1 refers to the content in the first 'capture group', in parentheses above $replacement = '<div class="myphoto">$1</div>'; // run preg_replace() on the $content $content = preg_replace( $pattern, $replacement, $content ); // return the processed content return $content; } add_filter( 'the_content', 'breezer_addDivToImage' ); Note that this will only affect images inside post content. If you want to wrap images that occur outside of the post body (such as featured images or images in custom fields), the most efficient way is probably to find where they occur and add the div wrapper to your theme file.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 1, "tags": "images, hooks" }
getting url in wp_enqueue_style I'm having trouble getting the second argument in wp_enque_style. Here's how my site is setup: * style.css * custom_style.css * index.php In a template, I have this code: $stylesheet_url = bloginfo('template_directory') . '/custom_style.css'; wp_enqueue_style( 'custom_style', $stylesheet_url ); Which isn't working. Any reasons why? The output is just the path to my template directory, outputted as raw text, which is obviously not the correct behavior.
To enqueue extra styles you should place the following code in your functions.php function my_custom_styles() { wp_enqueue_style( 'custom-style', get_stylesheet_directory_uri() . '/custom_style.css'); } add_action( 'wp_print_styles', 'my_custom_styles' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "css, wp enqueue style" }
jQuery UI Theme that aligns perfectly with the admin UI Anyone knows a theme that's not only close (like "smoothness"), but _really_ aligns with the look and feel of the admin UI?
Related trac ticket: Bundled jQuery UI should have CSS
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "css, jquery ui" }
If new comment posted in custom post - send notification to custom email from custom field I have custom post type "Art masters". Each post is master's profile. In their profiles isset custom fiels name "master_email". I need to send for master email notification every time if new comment is posted. How i can call post new comment function for use wp_mail? Thank you for help!
You can try something like this in your functions.php function send_comment_email_notification( $comment_ID, $commentdata ) { $comment = get_comment( $comment_id ); $postid = $comment->comment_post_ID; $master_email = get_post_meta( $postid, 'master_email', true); if( isset( $master_email ) && is_email( $master_email ) ) { $message = 'New comment on <a href="' . get_permalink( $postid ) . '">' . get_the_title( $postid ) . '</a>'; add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html";' ) ); wp_mail( $master_email, 'New Comment', $message ); } } add_action( 'comment_post', 'send_comment_email_notification', 11, 2 );
stackexchange-wordpress
{ "answer_score": 7, "question_score": 2, "tags": "comments, email, notifications, wp mail" }
Assign custom fields to multiple posts? I'm looking for a quick way to assign custom fields to a selection of posts that I hand pick. What's the best way to go about this? Currently I'm forced to edit each page and manually add the custom field. There's got to be a better way. And no, I don't want to apply it to a post type or a category.
Try magic fields plugin. That is the best custom fields plugin i've tried so far
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom field" }
WP E-Commerce Custom Meta > Serialized array I have an issue where I am adding custom meta to my products. Everything works fine until I update my product. This is before: !enter image description here This is after update: !enter image description here I am thinking it has something to with how it is pulling the data from the database. Anyone else have this problem before? Thanks in advance for your help.
This problem was caused by the addition of the WP "Custom Fields" metabox to the product post type.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, metabox, plugin wp e commerce" }
Changing Login Logo After modifying the code in my functions.php file to display a different logo on my login page, I'm getting a blank square instead. I've added a custom .png image (326x67) to my (child) theme's image folder, and the code I've added to `functions.php` is as follows: function custom_loginlogo() { echo '<style type="text/css"> h1 a {background-image: url('.get_bloginfo('template_directory').'/images/login_logo.png) !important; } </style>'; } add_action('login_head', 'custom_loginlogo'); Could it be a permissions problem (like an `.htaccess` file blocking the image)?
If you are using a child theme then maybe you should try the following code. Not necessary to put `!important` too unless some other plugin or code is overwriting it. function custom_loginlogo() { echo '<style type="text/css"> h1 a { background-image: url('. get_stylesheet_directory_uri().'/images/login_logo.png); } </style>'; } add_action('login_head', 'custom_loginlogo');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "login, logo" }
working with term_relationships table I have this little code to insert posts via custom form: $post = array( 'post_author' => 1, 'post_title' => 'my title, 'post_content' => 'my content', 'post_category' => array(3), 'post_type' => 'post', ); if ( $post_id = wp_insert_post( $post ) ){ echo 'post added!'; } but now I need to insert the last $post_id to `term_relationships` table, basic scheme of term_relationships: object_id | term_taxnomy_id | term_order ----------------------------------------- Wordpress have a function to update that table?, or I need to build a custom query?
Check this wp_set_object_terms().
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, custom taxonomy, query" }
Changing functions.php and .htaccess files Can I mess up my Wordpress site if I change `functions.php` file for my custom theme? One time I added some code to it and it gave me some PHP errors and my site was inaccessible. Luckily it was in the early stage of the website so I just reinstalled Wordpress. So, my actual question is - does `functions.php` file have any influence on any other file or database or any other part of the website? If I have a back up of the `functions.php` file, can I just replace the screwed up file via FTP or do I have to do something else? The same questions goes for `.htaccess` file - if I add this code: php_flag register_globals off to it, can I change something irreversibly or do I just upload the back up and all goes back to normal?
`functions.php` file is where you can do wonders with your theme without touching the core WordPress files. Most of the time the backup `functions.php` trick would work for you unless you aren't changing anything in the database with any of your action or filter hooks. You could check this link too -> < Regarding the `.htaccess` \- you should be fine by just replacing the backup file. Nothing irreversible done here.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, htaccess" }
How to access custom pages This should be a simple question. On websites like themeforest where you can buy themes others have built, when you preview the themes almost all the themes will have seperate pages for you to view seperate functionality For example if a theme has a portfolio, a blog with sidebars, a blog without sidebar, a blog with 2 sidebars. They will link you to different pages to see what each looks like. How do you do this? I mean if I just build a file called portfolio.php and put all my code to build that page, if I go to portfolio.php in the URI it isn't going to load that page, so how can I access a separate file, like portfolio.php
Paste the Following code to the top of your template: <?php /* Template Name: Portfolio*/ ?> <!-- Do stuff here--> This will make the Template selectable as a page template in the Backend :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "url rewriting" }
Specific folder and no thumbnail generation for media_sideload_image I am using media_sideload_image function in WordPress to upload images automatically from another location on the web. I want to add two more pieces of functionality. 1. Add these images to a particular folder in my system, which I will specify once within the code. 2. No thumbnails should be generated for these images, just import the image and put it in the folder, and attach to the post. How can I achieve points 1 and 2? Thanks
Ad 1) Take a look at `wp_upload_dir`. Ad 2) Try `remove_theme_support( 'post-thumbnails' );`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "media" }
Testing performance of WordPress files I would like to test the performance of PHP files in my installation, to find any bottlenecks. I already use plugins like Debug Queries and WPDB Profiler to watch the SQL Queries being generated, but I would like something that shows me the execution time of each php file to identify if some plugin is not optimised. Is there any plugin for this?
No. And even if there was, it would be probably useless anyway. You would get incorrect results, because a .php file might call slow functions from WordPress core files, and there are a lot of situations like this. You could try using the xdebug extension, it's pretty close to what you're looking for
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "testing" }
Is it possible to get_terms by author? I get terms from all my posts with `get_terms`, $tags = get_terms( 'mytags', '&number=5&orderby=date&order=desc&hide_empty=1' ); foreach ( $tags as $tag ) { echo '<a href="'.get_bloginfo('url').'/tags/'.$tag->slug.'">'.$tag->name.'</a>'; } Is it possible to get_terms included to the posts made by author? I try to add a list with all the terms (tags) in author.php template, thanks a lot!
Not directly, because terms are assigned to posts, not authors. You will need to query all posts, get their terms and authors, and then filter out terms which came with posts that have other authors than `get_query_var('author')`. Note that depending on the number of posts your site has, this kind of query could be very expensive. A better way would be to either record term IDs inside an user meta key during `save_post` (still kind of slow), or create your own table with the data you need (fast).
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "author, terms" }
Is it a bad practice to use switch_to_blog in the frontend? From Wordpress Codex (although related to the same function in WPMU and not WP3.0+): < it says: > _This switch is to be used for internal and admin area functions. It's too expensive a query to run on the front end._ in the new page for the same function in WP3+ there's no such mention. So, is it a normal or a bad practice to use switch_to_blog in themes? I have a multisite setup with 4 blogs and would like to use this function often to pull content from one to another.
For 4 blogs - most likely no. The problems start to appear when you have tens of thousands of posts+ across many blogs, and you want to do queries like getting the latest 10 posts from the network. You should test this yourself, and see if the use of that function (and the others that followed it) significantly affected site performance in some way
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development, multisite, front end, switch to blog" }
Removing Shortcodes from Child Theme I'm trying to remove the shortcodes from a child theme. In my functions.php file (for the child theme), I've put: function my_remove_shortcode(){ return ''; } add_shortcode('entry-twitter-link', 'my_remove_shortcode'); Where entry-twitter-link is a shortcode created in the parent. However, the entry still shows up on my posts. Ideas on what's wrong?
Try this out. Remove the already added shortcode then add the new shortcode on the init hook. function shortcode_cleaner() { remove_shortcode( 'entry-twitter-link' ); // Not exactly required add_shortcode( 'entry-twitter-link', 'my_remove_shortcode' ); } add_action( 'init', 'shortcode_cleaner' ); function my_remove_shortcode(){ return ''; }
stackexchange-wordpress
{ "answer_score": 13, "question_score": 3, "tags": "themes, shortcode, child theme" }
How to add a SAVE button to replace PUBLISH on a custom post type? I have a custom post type called 'contacts'. I want want to remove the status, post date and change the button from PUBLISH to SAVE. From what I can tell this may not be possible without changing core files (please correct me if I am wrong). So, instead of trying to hack the PUBLISH metabox, I have the ability to remove the PUBLISH meta box all together using the Access Manager plugin. But I need to know how to readd a SAVE button that works the same way PUBLISH would. Any ideas?
Not mine but modified from here. But if you pop this into functions.php or a plugin it will work. add_filter( 'gettext', 'change_publish_button', 10, 2 ); function change_publish_button( $translation, $text ) { if ( 'yourcustomposttype' == get_post_type()) if ( $text == 'Publish' ) return 'Save'; return $translation; }
stackexchange-wordpress
{ "answer_score": 10, "question_score": 1, "tags": "metabox, publish" }
Using full code instead of shortcode How do I use a full code for JW Player plugin, not just the shortcode? I need it so that I can try and use the full code for Lightbox plugin.
You can embed the JW Player anywhere by just using the html embed code: <script type='text/javascript' src='/path/to/jwplayer.js'></script> <div id='mediaspace'>This text will be replaced</div> <script type='text/javascript'> jwplayer('mediaspace').setup({ 'flashplayer': 'player.swf', 'file': ' 'controlbar': 'bottom', 'width': '470', 'height': '320' }); </script> If you have options that you want to change, you can always use the JW Wizard.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "jwplayer" }
Why is registering a sidebar for each page causing my sidebars to reset? I have the following code in my functions.php if ( function_exists('register_sidebars') ){ $pages=get_pages(); foreach($pages as $page){ register_sidebar(array('name'=>$page->post_title, 'sort_column'=>'ID','sort_order'=>'ASC', 'id'=>$page->ID)); } } It works beautifully to give me a sidebar for each page. The problem is that the sidebar contest are constantly being reset. Every time I go back to my widgets page, the sidebars are all blank. I can usually still see the contents on the actual site, unless I update something in a different sidebar. If I take out the loop and just use register_sidebar to register a single sidebar, everything seems to work fine. Any ideas why?
You need to wrap this in a function then add it to the widgets_init action. Also the register sidebar function does not have $arguments for sort_column or sort_order. I would also change the id to `'sidebar-'.$page->ID` add_action( 'widgets_init', 'prefix_register_sidebars' ); function prefix_register_sidebars() { foreach($pages as $page){ register_sidebar( array( 'name'=>$page->post_title, 'id'=> 'sidebar-'.$page->ID, 'before_widget' => '<div id="%1$s" class="'.$page->slug.' widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>' ) ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, sidebar, register sidebar" }
WP_Post_List_Table::get_views - Have post counts account for filters? Toward the top of the edit.php screens there is a list that displays post statuses along with the post count. I believe this is generated by WP_Post_List_Table::get_views. For example `All (7) | Published (6) | Draft (1)` Unfortunately, those post counts do not respect filters. I am using `pre_get_posts` to exclude certain posts. Even though only four posts are visible to the user, the numbers still reflect the total post count. I would like to see `All (4) | Published (3) | Draft (1)` I can't seem to find an action/filter to override these numbers (without using JavaScript).
You might want to remove those counts and replace them with your own. function insert_post_counts($views){ //Run your query to count posts //use wp_cache_set and wp_cache_get to optimize performance $edit_url = admin_url( 'edit.php' ); $views['all'] = 'All <a href="'.$edit_url.'">('.$all_count.')</a>'; $views['publish'] = 'Published <a href="'.$edit_url.'?post_status=publish">('.$publish_count.')</a>'; $views['draft'] = 'Draft <a href="'.$edit_url.'?post_status=draft">('.$draft_count.')</a>'; $views['trash'] = 'Trash <a href="'.$edit_url.'?post_status=trash">('.$draft_count.')</a>'; return $views; } add_filter('views_edit-post, 'insert_post_counts', 10, 1); You can reference how wp_count_posts works to generate the native post counts. Hope this helps!
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "post status, pre get posts" }
How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button I have a custom post type (called contacts). Since this post type is not working like a post, I don't want to show SAVE DRAFT, PREVIEW, Status, Visibility or Publish Date. The only options I want to show are PUBLISH & Move to Trash buttons. Is there a way to hide these other options? If not, how do I create a new PUBLISH & Move to Trash that I can add to a new metabox?
You can simply hide the options using CSS. This will add a display:none style to the misc and minor publishing actions on the post.php and post-new.php pages. It checks for a specific post type as well since all post types use these two files. function hide_publishing_actions(){ $my_post_type = 'POST_TYPE'; global $post; if($post->post_type == $my_post_type){ echo ' <style type="text/css"> #misc-publishing-actions, #minor-publishing-actions{ display:none; } </style> '; } } add_action('admin_head-post.php', 'hide_publishing_actions'); add_action('admin_head-post-new.php', 'hide_publishing_actions');
stackexchange-wordpress
{ "answer_score": 17, "question_score": 11, "tags": "metabox, publish" }
How to remove Filters from post admin page? On a custom post type, I want to remove the filters that show up on /edit.php (where all of the posts are listed out). I have a custom taxonomy that shows up as a filter that I WANT to keep, but I want to REMOVE the 'Show all dates' and 'View all categories' filters. Any ideas?
This is a very similar question to the one you posted here: How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button Please check my answer. You would simply need to add the IDs of the elements you wish to hide. You can traverse the DOM to target the elements you need: #posts-filter .tablenav select[name=m], #posts-filter .tablenav select[name=cat], #posts-filter .tablenav #post-query-submit{ display:none; }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 7, "tags": "custom post types, filters" }
How to disable posts and use pages only I am new to Wordpress theming and I would like to set up a Website that only has static content. Therefore would it make sense to disable posts and only use static pages? If so, is there an easy way to do that?
You can simply hide the posts menu by adding the following to your functions.php file: function remove_posts_menu() { remove_menu_page('edit.php'); } add_action('admin_menu', 'remove_posts_menu'); WordPress does not permit the disabling of the actual post type with the `unregister_post_type()` function. The condition is here: < // Do not allow unregistering internal post types. if ( $post_type_object->_builtin ) { return new WP_Error( 'invalid_post_type', __( 'Unregistering a built-in post type is not allowed' ) ); }
stackexchange-wordpress
{ "answer_score": 17, "question_score": 12, "tags": "pages" }
What is the best way to handle deprecated functions? Wordpress 3.3 has deprecated the add_contextual_help() functions and it's filters, so in order to continue supporting 3.0 - 3.2.1 and also comply with 3.3, I have done the following: global $wp_version; if ($wp_version >= '3.3') { // New method add_action("load-$admin_page", 'CrayonSettingsWP::help_screen'); } else { // Depreciated method add_filter('contextual_help', 'CrayonSettingsWP::cont_help', 10, 3); } Is there a better approach?
I don't see anything wrong with your approach. But I'm going to take a different track: **don't support older versions of WP**. The general impression I've gotten from the WP community is one of progress. By supporting the current version and forward you're helping to push the community towards using the most up to date version of WordPress. Excerpted from WordPress Plugin Development (which is a great book!): > In the WordPress development community, backward compatibility may sometimes be even looked down upon. Users are expected to stay updated with the latest version of the software.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 6, "tags": "deprecation" }
How can I list posts by author? How can I list posts as sub-items of authors? It should look like: <ul> <li>Author</li> <ul> <li>Post1</li> <li>Post2</li> </ul> </li> </ul> I have an array containing author data including `$author->ID`. My function looks like this: function add_custom_menu_items($items, $args) { $authors = get_users('role=author'); return $items.$authors_str; } add_filter( 'wp_nav_menu_items', 'add_custom_menu_items', 5, 2); Where can I get a list of posts?
This is a simpler solution, if you want a total control over the code and don't want to use a query. $authors = get_users('role=author'); if(isset($authors) && !empty($authors)) { echo "<ul>"; foreach($authors as $author) { $posts = get_posts(array('author'=>$author->ID)); //if this author has posts, then include his name in the list otherwise don't if(isset($posts) && !empty($posts)) { echo "<li>".$author->user_nicename."</li>"; echo "<ul>"; foreach($posts as $post) { echo "<li>".$post->post_title."</li>"; } echo "</ul>"; } } echo "</ul>"; } ?> You can also use this in your filter function.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, menus, list authors" }
How to get pages of parent (non-recursive)? I'd like to get all pages that are direct children of HOME_ID. Per < (see 'parent' parameter), I think this should be done with get_pages: $top_pages = get_pages(array('parent' => HOME_ID, 'sort_column' => 'menu_order')); but this returns no results. I get results back if I plug in 0 for HOME_ID. No sweat because I can achieve what I want with: $menu_wp_query = new WP_Query(); $top_pages = $menu_wp_query->query(array('post_type' => 'page', 'post_parent' => HOME_ID, 'orderby' => 'menu_order')); But still uncomfortable; is this a bug? Using WP 3.2.1 Thanks.
Assuming that, by "HOME_ID", you are referring to the **static Page used to display the Site Front Page** , then you want to use `get_option( 'front_page' )` to get the **ID** for this page: <?php $menu_wp_query_args = array( 'post_type' => 'page', 'post_parent' => get_option( 'front_page' ), 'orderby' => 'menu_order' ); $new_wp_query = new WP_Query( $new_wp_query_args ); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, pages" }
How to place random widgets in the Wordpress sidebar? My pages have a sidebar with too many widgets, and it looks bad when the content is short and the sidebar is too long. I want to randomize the widgets I'm showing in the sidebar. Meaning I will add all the potential widgets to the sidebar, and it will randomly only display a few. I would also like some control over this, for example to have a few widgets always appear, and only the rest randomized. I tried finding relevant plugins, but the only ones I found just randomized images or posts.. never different types of widgets.
Here comes the workaround solution discussed in the comments: **functions.php:** add_action( 'widgets_init', 'talfluxive_register_sidebars' ); function talfluxive_register_sidebars() { // register five random widget areas register_sidebars( 5, array( 'name' => 'Random Widget Area %d' ) ); // register two fixed widget areas register_sidebars( 2, array( 'name' => 'Fixed Widget Area %d' ) ); } **sidebar.php** dynamic_sidebar( 'Fixed Widget Area 1' ); dynamic_sidebar( 'Random Widget Area ' . rand( 1, 5 ) ); dynamic_sidebar( 'Fixed Widget Area 2' ); This example code is very minimal and could be improved in many ways but it works and should serve as a good starting point. _PS: I really like the random widget idea. I will look for a better solution when I have more time. It's a good plugin inspiration :)_
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugins, widgets" }
How to limit character length in BuddyPress function output BuddyPress has a function (bp_member_profile_data) that pulls profile data into a members loop which looks like this: <?php bp_member_profile_data( 'field=Organization' ); bp_member_profile_data( 'field=Brief Biography' ); /*** * If you want to show specific profile fields here you can, * but it'll add an extra query for each member in the loop * (only one regardless of the number of fields you show): * bp_member_profile_data( 'field=the field name' ); */ ?> I'm wondering how to limit the echoed length of Brief Biography. I've looked at the Bavatosan example and substr but they're kind of beyond me at this point in terms of knowing where to modify them.
I think buddypress has a get* version of that function that returns the value instead of showing it on the screen. So just cut the returned string after a certain amount of characters, like 50: $profile_bio = bp_get_member_profile_data( 'field=Brief Biography' ); if(strlen($profile_bio) > 50)) $profile_bio = substr($profile_bio, 0, 50).'...'; echo $profile_bio; If there's no get function you can always use output buffering: ob_start(); bp_member_profile_data( 'field=Brief Biography' ); $profile_bio = ob_get_clean(); // rest of the code is the same
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "functions, buddypress" }
posts_per_page no limit I want to return ALL posts with `query_posts`. I tried setting `posts_per_page` to a really high number, but `query_posts` freaks out and doesn't return any posts. What is the correct way to query posts without a limit? $args = array( 'post_type' => 'post', 'cat' => '22,47,67', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'depth' => 1, 'posts_per_page' => ? );
-1 is your answer! Look for `posts_per_page` here. $args = array( 'post_type' => 'post', 'cat' => '22,47,67', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 1, 'depth' => 1, 'posts_per_page' => -1 ); **Important caveat** : This can result in a very huge query that can bring the site down. Do this only if you are sure your database can handle it. Not in public themes or plugins.
stackexchange-wordpress
{ "answer_score": 107, "question_score": 53, "tags": "query posts" }
Wordpress “Categories to tag converter” not working on imported Blogger posts I just imported a blog from blogger to wordpress recently. The blog consisted of about 3500 tags in total. On importing them into wordpress, they were converted to categories for some reason. I have installed and the **categories to converter** plugin by wordpress that allows you to convert them to tags. On the converter page, i have checked all the categories (using the **check all** button) then clicked on the **convert to tag** button. However, after waiting for the conversion to take place, the page refreshes and goes back to exactly how it was before i clicked on the button, i.e, nothing is converted. Tried it several times and even uninstalled and re-installed the plugin, but no luck. Was wondering if someone else has had the same problem and resolved in. I'd appreciate any help Many thanks in advance.
You can always perform the transformation at the database level (field taxonomy in wp_term_taxonomy classifies a taxonomy term in a category or tag )
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, tags, categories" }
the blog owner multisite In a multisite, how can I get the ID of the owner of the current blog? I know how to get the current blogs Id using get_current_blog_id(), so given that ID, how would I fetch the ID of the owner of that blog? (there's just one owner per blog.)
I came up with this solution for a direct query, but I'd still like to know if there's a template tag I've missed. $blog_id = get_current_blog_id(); $querystring = "SELECT `user_id` FROM `wp_usermeta` WHERE (meta_key LIKE 'primary_blog' AND meta_value LIKE $blog_id) LIMIT 1"; $blogownerid = $wpdb->get_var($querystring);
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "multisite, users" }
How can i put "posted x minutes ago on my posts? wordpress by default writes the the date on posts, but how can I transform it to : "x" time ago ?? like 3 days ago, or 5 minutes ago ??
function k99_relative_time() { $post_date = get_the_time('U'); $delta = time() - $post_date; if ( $delta < 60 ) { echo 'Less than a minute ago'; } elseif ($delta > 60 && $delta < 120){ echo 'About a minute ago'; } elseif ($delta > 120 && $delta < (60*60)){ echo strval(round(($delta/60),0)), ' minutes ago'; } elseif ($delta > (60*60) && $delta < (120*60)){ echo 'About an hour ago'; } elseif ($delta > (120*60) && $delta < (24*60*60)){ echo strval(round(($delta/3600),0)), ' hours ago'; } else { echo the_time('j\<\s\u\p\>S\<\/\s\u\p\> M y g:i a'); } } then put `k99_relative_time()`; in theme file where you want this to appear.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 7, "tags": "timestamp" }
How much should I worry about these messages? I received about 50 messages today with the similar message: > WordPress Firewall has detected and blocked a potential attack! > > Web Page: domain.com/index.php?option=com_simpledownload&controller=../../../../../../../../../../../../../../../proc/self/environ%00 Warning: URL may contain dangerous content! Offending IP: 211.147.221.42 [ Get IP location ] Offending Parameter: controller = ../../../../../../../../../../../../../../../proc/self/environ > > This may be a "Directory Traversal Attack." How much should I worry about these? It came from multiple IP addresses throughout the day.
This is very common, it is a malicious query string most likely (99% time) done by a bot, I think `option=com_simpledownload` is actually a Joomla plugin, so obviously it won't effect WordPress. You can see the detials here, <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "security" }
Show one of the taxonomies always as default I have custom post type called **staff** that has custom taxonomy called **departments**. I wanted the frontpage of the staff (archive-staff.php) to not show ALL the staff members, but actually the first department (lets say there are 3 departments.) My archive page starts like this: global $wp_query; $args = array_merge( $wp_query->query, array( 'post_type' => 'staff', ) ); query_posts( $args ); while (have_posts()): the_post(); // ... I have no clue how to go from here. I also need to display the current departments title.
This is what worked for me: // Custom taxonomy $custom_taxonomy = 'department'; // Get the current department if (!$current_department = $wp_query->query_vars[$custom_taxonomy]) { $get_all_departments = get_terms($custom_taxonomy, array( 'number' => 1 )); $current_department = $get_all_departments[0]->slug; } // Get the departments information $department = get_term_by('slug', $current_department, $custom_taxonomy); So the `$current_department` is the slug of the current taxonomy and `$department` is an array of the current taxonomy.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom taxonomy" }
Remove category from url I want to remove /category/ base from the permalinks. I tried the solution ** but if i try pasting this in functions.php, i get the 404 error. I also tried `RewriteRule ^category/(.+)$ /$1 [R=301,L]` by pasting in **.htaccess** , but still, i get 404 error.
To make things easier why don't you use this plugin -> WP No Category Base
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "functions, htaccess" }
image background is cut < that's my webpage that has a problem in the background, I don't even declared it as no-repeat but still the background was cut at the bottom. I'm confused because in the other page, it's not cut, like this one <
Your background image repeats all right - but there's a white bar at the bottom of your image... <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "css" }
add text to the top of category page I want to add the text to top of each category page. I am using a plugin ** . With the help of this plugin, i am able to add extra field to my categories, but how can i display that. eg :- if i want to display category description, i used `<?php echo category_description(); ?>` similarly, how can i display custom field value.
May I suggest using one plugin that I use for my sites ( I am a web-developer)? I Use Extra category content plugin (< if I want to put any kind of content (text, image, link, etc) before the post listing in a category. Just install the plugin, edit a category to add some extra content and add in the template the code `<?php echo the_extra_category_content( ); ?>`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "categories" }
Reordering themes in admin panel I've been searching for a hook to change the order in which themes are displayed in the admin panel (i.e. wp-admin/themes.php) but so far haven't been successful. Is there an existing hook to do this, or another workaround so I can have a custom non-alphabetical ordering - i.e. have certain themes display before the rest?
The `get_themes` function passes the available themes to the theme list table class and is hardcoded with a call to `asort` the array, with no filters available anywhere along the way that i can see. So in short, not possible at present due to an absence of hooks(at least as far as my observations go). **Relevant files:** < < <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "plugins, themes, wp admin" }
how to insert a HTML form into a javascript popup? I'm working on a plugin that generates a list of candidates as output. For each candidate there is a link (View Details) that once is clicked, a popup appears. I need to put a simple contact form into that popup, so when a visitor click on the candidate's link, the popup appear and the visitor can get into touch with the website owner and ask references about that candidate. As I said, all this is done by a plugin. I'm having problems in making a simple modal contact form from that plugin. Any idea in how to do that?
A) It's not a WP Question as long as it's not a specific plugin (link?). B) Do it with jQuery: var str = <?php echo $user_id.'etc.'; ?>; var container = jQuery( '#contact_form_popup_id' ).html(); jQuery( container ).text( str );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, javascript, html, contact" }
Unable to process php via shortcode I've been searching around for a fix to this and while I definitely have a much better understanding of my issue (thanks to similar queries posted by others) I am still not sure of the solution. I am writing a shortcode as follows: function cup_bc_shortcode(){ $html = file_get_contents('/html/cup_bc_layout.php', true); return $html; } add_shortcode('budgetcalc', 'cup_bc_shortcode'); The file 'cup_bc_layout.php' contains html and PHP. The PHP code is being rendered as text on output rather than being processed by the browser. Is there anyway to include the PHP file in a manner similar to this? I appreciate that the shortcode must return the output in order to work but I'd prefer not to have to build this up as a single string from within this function if I can help it. Also I am quite new to PHP so even the most obvious of solutions may have eluded me. Your help greatly appreciated.
The problem is that you are using `file_get_contents()` which only gets the content of the file (hence the name) if you need to render(evaluate and process the php file) then just use `include()`. But also if your `cup_bc_layout.php` file echo's out something then you should put the include inside an object buffer and then return the value to make sure the shortcode works properly. So try this: function cup_bc_shortcode($atts,$content=NULL){ ob_start(); include('/html/cup_bc_layout.php'); $return_val = ob_get_contents(); ob_end_clean(); return $return_val; } add_shortcode('budgetcalc', 'cup_bc_shortcode');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, shortcode" }
Don't display html if function returns nothing This question is very similar to the one below however it requires a different solution. Don't display html if custom field is empty I'm using the plugin Related Posts Thumbnails but i'm using the template tag in my template file to display related products. <?php get_related_posts_thumbnails(); ?> Plugin Source I've got this contained inside of a div with a title so the output looks a bit better. However if there isn't any related products i need it to hide the div otherwise it just displays an empty area. This is the code i'm using. <div id="relatedproducts"> <h1>Related Products</h1> <?php get_related_posts_thumbnails(); ?></div> Is it possible to not show this div if the function returns no related products? Thanks
<?php global $related_posts_thumbnails; if ($related_posts_thumbnails->get_html()) { ?> <div id="relatedproducts"> <h1>Related Products</h1> <?php get_related_posts_thumbnails() ?> </div> <?php } ?> A quick look at the `get_related_posts_thumbnails()` shows that it is simply echoing the HTML returned from the `get_html()` method of the `$related_posts_thumbnails` object. By checking the returned HTML first, you can make sure it is not an empty string (or any falsy value). Note for the plugin author: picking the name `get_related_posts_thumbnails()` and making it _echo_ the output is quite unintuitive. Other WordPress functions use the `get_` prefix for functions that return data, and leave it out to echo it. For example: `get_bloginfo('url')` vs `bloginfo('url')`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions" }
How to add a filter to the get_body_class function? I see it is possible to use add_filter with the `body_class` function, but I'm needing to add one to the `get_body_class` function. How can I add a filter to a function that is not included in the list of already available filter hooks? Thanks.
The `body_class()` function simply calls the `get_body_class()` and creates a HTML class string from it. function body_class( $class = '' ) { echo 'class="' . join( ' ', get_body_class( $class ) ) . '"'; } So, the `body_class` filter applies to both functions.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "filters, hooks" }
remove WYSIWYG editor but keep media button i need to remove the deafault TinyMCE editor from pages, i used this: remove_post_type_support( 'page', 'editor' ); But it removes also the media button that i need
You may want to have a look at the brand new wp_editor function in WP3.3, there's an option tiny_mce=true/false: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "tinymce" }
Symbolic Links for themes - linking one theme to many wordpress installs This discussion relateds to plugins: Symbolic Links on dev box with plugins and stylesheets I was wondering if the same problem exists for symlinking a theme to many different wordpress installs. **Example structure:** > domain/footheme/ <\- theme resides here **The following domains symlinks created here:** > domain/myfoo.com/wp-content/theme/(footheme) > > domain/myfoo2.com/wp-content/theme/(footheme) > > domain/myfoo3.com/wp-content/theme/(footheme) **Example Symlink Creation** `ln -s domain/footheme domain/myfoo.com/wp-content/theme/footheme`
Due to project constraints i ended up just creating custom themes for both. If i was to approach this now i would probably manage it by creating a git repository and maintaining multiple git submodules
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "themes" }
Gallery Image Numbers? Is there a way, in an image gallery, to display what number the image is in the gallery in the image.php template? I'd like to incorporate this into my next / previous button area. For example, if I'm on the first image out of twenty it would say "1 of 20".
This should do it: global $post; $ancestors = get_post_ancestors($post->ID); $photos = get_children(array( 'post_mime_type' => 'image', 'post_parent' => array_shift($ancestors), )); $index = 0; foreach($photos as $photo){ $index++; if($photo->ID === $post->ID) break; } printf('%d out of %d', $index, count($photos));
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "gallery, images" }
Can posts have parents? Are posts supposed to have parents? If so, what would that mean for a post to have a parent? Also, if there are some constraints to posts having parents, then where is that enforced? Not in the DB as I see it.
Out of the box, no, posts can't have parents. They can be assigned to categories, which can be organised hierarchically. Pages, however, can have parents and you can build a menu structure out of them by using that feature. As to where this is enforced: The parent of a post is stored in the column "post_parent" in "wp_posts". It's not really enforced as such, just the default UI doesn't give you an option to set it and default WP coding doesn't use that value for Posts. It wouldn't be too difficult to create a custom post type to have posts with parents though.
stackexchange-wordpress
{ "answer_score": 16, "question_score": 17, "tags": "posts, database" }
How Do I Programmatically Force Custom Permalinks with My Theme? I'm making a custom theme. It's a highly specialized theme to make WordPress into like an application rather than a CMS system or blog. For instance, a Dental Office Scheduling System (with CMS and widget capabilities), as an example. Because my theme needs pretty URLs to work properly, something I really need is for the .htaccess file to be that default that gets created only when someone sets Permalinks to Custom (and then types in something like %postname%). How do I trigger that in WordPress, programmatically, so that it creates this? I mean, I could probably overwrite the file myself during theme activation, but the better thing would be to use the WordPress API for it.
To fully enable permalinks, you also need to ensure that .htaccess is also created. To do that, you need to set an option and flush the rules with a Boolean. global $wp_rewrite; //Write the rule $wp_rewrite->set_permalink_structure('/%postname%/'); //Set the option update_option( "rewrite_rules", FALSE ); //Flush the rules and tell it to write htaccess $wp_rewrite->flush_rules( true ); If you use this in a plugin, it needs to be in the `init` hook, **_not_** the `load` hook. If it's in the `load` hook, it will throw an error saying `$wp_rewrite` is null. **Important:** You should also have a conditional so this is only set once. (You can create an option and check if it's set, if not then you run this permalink code and set that option) I also typically check if it's the admin side and only run it if it is.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "theme development, permalinks, htaccess" }
Wordpress cookies I am trying to set a cookie on click via setcookie('mycookie', 1, time()+60*60*24; but I can not seem to get it working . If i click the button - when I check my cookies, it is not there .
Cookies are set on the session BEFORE the page starts to load. Therefor - This function will set the cookie for the NEXT time the page is requested. you can not (as far as I know ) set a cookie onclick without any javascript help, becasue when at the time the page is rendered (and your click button) - all the cookies are already set. If you are familiar with jQuery - there are some very good plugins that can help you set a cookie via JS and "refresh" the cookies session. Some of them , will actually refresh the cookie in a way that will trigger also the "normal" wp cookie to be updated .
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "cookies" }
Is there a way to add a link directly into this media query? I am running this query which pulls all of the images attached to a particular post and outputs them into a slideshow (See example here - < Is there a way that I can directly output a link (So that the larger image gets displayed in a lightbox) into this query as adding link tags doesn't seem to work <?php $args = array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID); ?> <?php if ( $photos = get_posts($args) ) : ?> <?php foreach ( $photos as $photo ) : ?> <?php echo wp_get_attachment_image($photo->ID,'thumbnail'); ?> <?php endforeach; ?> <?php endif; ?>
I think you can use `the_attachment_link` or `wp_get_attachment_link`. < < **Example** the_attachment_link( $photo->ID, false, false, true );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query, media" }
Hide menu items for visitors and filter based on role In my menu i've got some menu items that i don't want to show to people who aren't logged in. One of these i only want to show to logged in users of a certain roles the other to everyone logged in. So one of them is called 'My Printer'. This should be visible to everyone that is logged in. The other is called 'Partners'. This should only be visible to users with the partner role. I've tried using Role Scoper but i find it very difficult to use and it doesn't make a lot of sense. It also interferes with a lot of other things as well which i don't need. Is there anyway i can hide menu items based on their role? Thanks **EDIT** I've created the menu using the admin and placed that menu in a theme location. The menu items i want to hide are in this menu. Thanks for the 2 answers below, but neither achieve what i'm after.
I've created the menu using the admin and placed that menu in a theme location. The menu items i want to hide are in this menu. Thanks for the 2 answers below, but neither achieve what i'm after.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "menus, user roles" }
What plugins can I use to feature (affiliate) products on my blog (from Amazon.com)? I know Amazon.com will pay affiliates (in some states, depending on tax laws) who send users to their website to buy a product. I've also seen some Wordpress sites that feature Amazon.com products with links that seem to be affilate links. Are there any good plugins for featuring affilate products from Amazon.com (or other services?)
Amazon product in a post plugin is the best i have tried so far. It can be used for all amazon regional websites like amazon.co.uk,amazon.fr etc
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, e commerce" }
WP 3.3 makes it possible to add meta box to Category Editor Screen? I have a plugin that appears on the post and page editor screen and parses the editor content and reports back some info to the user. I need this same plugin to appear on the category editor screen and report against the "Description" field. Any ideas how it can be done? I'm hoping WP 3.3 may make it easier to implement. Here's how I'm adding the plugin to the editor screens: add_action('admin_menu', 'my_post_options_box'); function my_post_options_box() { add_meta_box('my-plugin', __('My Plugin'), 'test', 'post', 'side', 'high'); add_meta_box('my-plugin', __('My Plugin'), 'test', 'page', 'side', 'high'); } I'd like to be able to add this: add_meta_box('my-plugin', __('My Plugin'), 'test', 'category_edit', 'side', 'high');
As far as i can tell no new hooks on this screen to handle metaboxes :( the only way i see is to use the `edit_category_form_fields` with a function that prints out the fields and save them using `edited_category` I've posted a tutorial about this a while a go **`WordPress Category Extra Fields`**
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development" }
Some questions regarding filter 1) Take a look at this example add_filter( "xxx_xxxxx", "blah_blah" ); function blah_blah(){ echo "filter added"; } `xxx_xxxxx` can be anything like my_filter or it should be one of the name listed here. 2) Lets say i have some content in my theme outside `the_content` loop. Example <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <div class="entry-content"> <?php the_content(); ?> </div> <div class="custom-content"> <p>Blah blah some text goes here</p> </div> <?php endwhile; ?> Is there a way to filter `Blah blah some text goes here` text? Thanks
It depends whether you're trying to hook to an existing filter or hook to one you've made, looking at your second code sample suggests you're asking about making your own filter. And, yes you can add your own, something like this is valid inside your loop. <?php echo apply_filters( 'my_blah_filter', '<p>Blah blah some text goes here</p>' ); ?> You can then hook that filter, as you would with regular WordPress filters, eg. add_filter( 'my_blah_filter', 'my_filter_for_blah' ); function my_filter_for_blah( $filter_content ) { // Uncomment the next line to see the effect of not replacing it $filter_content = 'new content'; return $filter_content; } add_filter( 'my_blah_filter', 'wpautop' ); Let me know if that helps. :)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "filters" }
WP 3.3 Tooltips API? Does anyone have a tutorial on how to implement the new Tooltips API into a theme or plugin? I'm eager to tap into this to help first time users of my theme and plugins. From mashable'e excellent intro to 3.3... > 1. New Tooltips > > > This may seem a bit annoying to more experienced users, but it can prove quite useful for most. > > Tooltip popup bubbles now display to help guide users through the new features found in WordPress. You’ll see one of these immediately upon upgrading, which points to the new admin bar. > > _**> Developers are able to use these popups to add their own feature tours. This will prove useful for theme and plugin authors who need an easy way to walk their customers through their WordPress products_**
I can't come up with good quote, but as far as I understand from chatter - pointers are not considered public (available for use outside core) for version 3.3 So essentially there is no API to use yet.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "plugin development, theme development, tooltip" }
Hotel reservation plugin you would recommend What hotel reservation plugins for Wordpress would you recommend for a Small hotel that has not more than 25 rooms? It needs to display room availability and can accept payment online.
I would suggest this plugin: < There is a free version and a few very nicely featured paid upgrade services depending on your needs on their website.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, plugin recommendation" }
3.3: How do you hide the new dashboard welcome panel? I have tried various versions of this here: unset($wp_meta_boxes['dashboard']['normal']['high']['dashboard_wp_welcome_panel']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_wp_welcome_panel']); unset($wp_meta_boxes['dashboard']['normal']['core']['wp_welcome_panel']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_welcome_panel']); unset($wp_meta_boxes['dashboard']['normal']['core']['welcome_panel']); I have tried looking this up but as there is not much documentation (there is but there isn't ) on it yet it is kind of hard. I was wondering if someone could please help me out. I would really appreciate it. Thanks. :)
If you're using multisite, there's a plugin you can network activate to disable the welcome panel on all new sites. It's aptly named "Hide Welcome Panel for Multisite." If you just want to do this for a typical (single site) installation, it's also pretty easy. The welcome screen is shown for a user if a specific meta key is set. So, add the following to a plugin and activate it ... add_action( 'load-index.php', 'hide_welcome_panel' ); function hide_welcome_panel() { $user_id = get_current_user_id(); if ( 1 == get_user_meta( $user_id, 'show_welcome_panel', true ) ) update_user_meta( $user_id, 'show_welcome_panel', 0 ); } This code is adapted directly from the above-mentioned plugin, but I haven't had a chance to personally test it ...
stackexchange-wordpress
{ "answer_score": 4, "question_score": 6, "tags": "admin, wp admin, dashboard" }
Update some database fields when post is saved I have a class that will count the Lines of Code, Source Lines of Code, and the Code disk space used. I would like to save these values into the database so that these values can be calculated only when a new post is saved or updated instead of running the code on every page view So my question is, what is the best way to make sure these are added/updated everytime a new post is made and everytime that post is updated/edited. Also where should I store these, in a custom meta field? If so, how can I make sure that the meta box does not show up on the page, it should all be done behind the scenes
Best way for storing them is Wordpress' Options Mechanism. ANd best way to trigger it when a post saved is using Wordpress save_post action. Example : add_action( 'save_post', 'count' ); //Execute count() when a post saved/updated function count() { your codes here ... //save them to DB update_option("lines-of-code", $lines); update_option("disk-space", $diskspace); ... }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, mysql" }
Why won't child theme's style.css override plugin's css I am using my own child theme for twentyeleven, and I've made some changes to some plugin's css classes in my child style.css. The problem I'm having is that if I add a new css attribute to a class from the plugin's css, then it will make the change. But, if the attribute is already declared in the plugin's css, it relies on that. How can I make my child theme's style.css take precedence over the plugin's css files? Here's an example of what happens from firebug (the first css file is from the plugin, the second is from my child theme): !enter image description here
I suggest that you use specificity to do this. Right now both rules are of equal value. What div holds the div "product?" If the Div is called "wrapper" your code could look like this: body div.product div.images img { ...... }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "css" }
How to limit the number of posts a user can publish based on user type I am creating a member only wordpress site that will restrict the number of custom posts a user can publish (Custom post type = contacts) based on their role. I will have 4 roles: Role 1 = 25 posts; Role 2 = 150 posts; Role 3 = 300 posts; Role 4 = unlimited posts Is this possible to do with WP hooks?
I found this plugin Bainternet Posts Creation Limits witch let you add how meny post a user, role or group can create. The plugin description says: Main Feature: * Limit number of any post type creation. * Select Post Status to count. (NEW) * **Limit number of any post type creation by user Role. (NEW)** * Limit number of any post type creation by user ID. (NEW) * New Limit Rule System (faster and stable). * Custom blocked message For each Rule. (NEW) * MultiSite Support. (Fixed and works better then before) * ADD NEW Links are removed when limit is reached (NEW) * 0 Now means ZERO so Its actually blocks the user from creating at all. * Shortcode to limit front end post creation (NEW). It looks like you have a function that matches your question: Limit number of any post type creation by user Role.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, count" }
Cannot use 'CSS' in post title **Issue?** Whenever I use the term 'CSS' in a post title, the rest of the title (after the term 'CSS'), is inserted at the top of the single post page. **What steps will reproduce the problem?** 1\. Create a new post. 2\. Type 'CSS' somewhere in the post title. 3\. Preview/publish the post. **What is the expected output? What do you see instead?** I expect to see the page title appear as normal, which it does. However, at the top of the page, above the opening body tag, everything in the title after the term 'CSS' is inserted. **What version of the product are you using?** WordPress 3.3 Here is a link to illustrate the issue: <
Disable all plugins. One of them puts all words with capital letters in a `<span class="caps">` container. In <meta property="og:title" content="test <span class="caps">CSS</span> title" /> … this closes the `<head>` section automatically because output is not allowed in `<head>`. If you have found the plugin tell its author about the Bug. I’m sure s/he wants to know about this. Parsed code in Opera’s debugger: !Parsed code in Opera’s debugger
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "title" }
wordpress Search function is not working My wordpress Website Version is 2.8.1,This is the Custom wordpress website done by 2 years ago.[Link Removed... i got Solution][1]Now Search functionality is not working(It was working well earlier.) My Client told **Don't Upgrade the Version**. so here we need to replace the old search function with newer Search function. My **searchform.php** <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/" style="padding-bottom:30px;"> <input type="search" value="search..." name="s" id="s" class="inputbox" onblur="this.value='search...';" onfocus="if(this.value=='search...') this.value='';" /> <input type="submit" id="searchsubmit" value="" /> </form> There is no more Files like " **search.php"** . I don't know how to replace the older search function with newer one.So please any one guide me. or any search plugin is do this work. Thanks in advance. This Thread is Closed...
OK, just to clarify your question. Your problem is with the search form not appearing in the top right corner? All I see there is a search image, but no input field. The search functionality does work on your site, eg: < but something's not configured properly there either, as it's not returning any results. Now, as to why your search form is not appearing, there's not enough code or information to figure this out. Have you tried turning on WP("debug") in wp-config.php? define('WP_DEBUG', true);
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "plugins, functions, plugin recommendation, search, function exists" }
Including two taxonomies in a permalink structure I am trying to get my head around the permalink structures on Wordpress sites, and I'm a bit stuck with what I'm trying to achieve: My current permalink structure: **/%category%/%postname%/** I have a custom-post type called 'city', and I want to create a structure like below: **mydomain.com/asia/china/beijing** So just to explain this structure: **asia** \- This is a term under a taxonomy called **'continent'** **china** \- This is a term under another taxonomy called **'country'** **beijing** \- This is the actual custom-post type post with title **'Beijing'** So I basically have two taxonomies (continent and country) linking to my **'city'** post type. So the way I see it, I need a structure like this: **mydomain.com/(taxonomy-continent)/(taxonomy-country)/(custom-post)** But I cannot seem to figure out how to achieve this with the permalink structure. Any help would be greatly appreciated! Thanks
You don’t need these two taxonomies. Just make your custom post type for places hierarchical and set countries and continents as parents. WordPress will build your permalinks then exactly as you want it. After you’ve created the first post you get a selector for page parents from which you can choose: !enter image description here
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "custom post types, custom taxonomy, url rewriting, permalinks" }
Breadcrumb NavXT plugin - exclude 'home' page Does anyone know how to exclude the breadcrumb from appearing on the 'home' page only using this plugin? I have currently got it set up in the header template and so it is appearing on every page.
Opne you header.php file and look for something like this: <div class="breadcrumbs"> <?php if(function_exists('bcn_display')) { bcn_display(); } ?> </div> then before the call for `bcn_display();` make sure you are not on the home page so basicaly replace `bcn_display();` with: if(!is_home() && !is_front_page()){bcn_display();}
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, breadcrumb" }
Index template and Home page Sorry if this seems silly but I am new to WP. I realise that Index template is the most important file. Is it ok to have Index as your "home" page, and can you just assign the Index template to the home page when setting it up in the back-end?
Use home.php just as Sisir said. Copy the content from index.php to that file and you are all set. home.php tells wordpress that that page should be the homepage in a theme so no backend settings needs to be changed.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "templates" }
Query Posts Incorrectly Displaying Tags Archives When I go to a tag archive ( < for example) ALL the posts on my blog are being displayed, not just the posts with that tag - and I'd like to fix this. Here's my tag map, click any tag and ALL posts are being pulled < Here is how I am querying posts (there is custom code for an options panel to display the number of posts assigned): <?php $per_page = get_option('to_count_archives'); query_posts("cat=${cat}&posts_per_page=${per_page}&paged=".$paged); if (have_posts()) ?> <?php while (have_posts()) : the_post(); ?>
create a tag.php template from a copy of archive.php or category.php, and remove the 'query_posts' line from the code.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, tags, archives" }
Can't access Dashboard after WordPress 3.3 Update? Hi I am having a problem, I updated my wordpress site to version 3.3 and the site itself seems to be working fine except I cant log into the dashboard anymore. When I login using my admin details it keeps re-directing me to /forums/profile page for admin user. Please can anyone help me out or has anyone came across this problem before? Thanks Louise !enter image description here
Okay, seems like the user permissions got changed. Did you have a plugin that manages user roles? Anyhow, I'm assuming that you have database access. Check the role that has been assigned to the user. You may have to change this manually to an administrator by editing the database. Hope this helps. :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "cms" }
WordPress or Drupal for data-heavy content site Looking to build a very data-heavy content site and not sure if what I'm looking to do can be accomplished in WordPress (my preference) or even in Drupal for that matter. The problem isn't the content, which I assume Custom Post Types (or maybe Pods??) could do. It's the relationships between the content. Basically want to build pages for individual baseball players, with a some stats (not totally crazy, just basics), RSS headlines from various sites, photos, etc. but with relationships to teams, individual games played in, etc. That's where I'm unsure. Even in Drupal it looks like I would have to use the Entity reference module to accomplish this. So, player is on a team, a team plays in a game, etc. being able to sort and browse by these relationships. Thoughts on if WordPress (or Drupal, or other) is up to this or I would have to go complete custom app/framework? Thanks!
I would go with WordPress for the simple reason that it takes less time to create custom websites (your in a WordPress Support site did you think you would get a different answer?). It sounds like you need to read up on custom post types and taxonomies. I don't see why the requirements you've mentioned couldn't be handled by CPT's if you set it up right. Here are a few resources to some info that may help: Justin Tadlock's CPT Tutorial (an older article, but still useful). New2Wp.com's CPT and Taxonomies The Right Way Tutorial WPTutts Tutorial That should give you a good start on how to use CPT's and Taxonomies to catagorize your content into the needed fields.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, comparison" }
Why doesn't WP recognize images in posts like other content? I've noticed a problem I have with images in my posts: they seem to go unnoticed to my CSS. For example, I have a span tag that is adding a 100px margin to the top of itself under the last paragraph in each post. But when an image is present the span tag seems to ignore the image as part of the paragraph content. There is no 100px margin created. I'd usually say this is a CSS problem... but I think it may be a WP problem. Any thoughts? Website
It's because you've floated your image on line 745 of your CSS. You've cleared the span, but the margin property still won't if there's a floated element above... Change the margin to padding, that should fix it..
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css, core" }
How do you get the post thumbnail size? I know how to _set_ the size of a post thumbnail image using the WP Admin Media Settings or using this function: set_post_thumbnail_size( 150, 150 ) But how would one get the image **width** _and_ **height** that have been set for an image thumbnail size? I'd like to be able to do something like this: get_post_thumbnail_size(); // return array(150, 150) How would this be done? Is it by using `get_option()`, and would the options keys be for thumbnail width and height?
When an image size is added either by WordPress(`add_image_size`), or by a plugin or your own custom code it gets added into the `$_wp_additional_image_sizes` global, i can't find a similar function for pulling data from that global, but you could certainly just look inside the global to determine what width and height a registered image size has. **Example:** global $_wp_additional_image_sizes; // Output width echo $_wp_additional_image_sizes['post_thumbnail']['width']; // Output height echo $_wp_additional_image_sizes['post_thumbnail']['height']; Of course just be sure to reference those values at a point after you've set the size. So if for example you're setting the thumbnail size during init, you'll need to make sure to do whatever you need to after that point(else you'll get back the sizes as they were prior to setting them). Hope that helps.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 16, "tags": "post thumbnails, images" }
Are widgets meant to be used outside of sidebars? Are widgets meant to be used outside of sidebars? My case: I have this html block which I want to use every time I display a post with category of "Story". I was going to make a widget to reduce duplicate code. Is there a better way to apply this html block to every displaying of a "Story" post?
If the category is `Story`, then make a template file, and name it as `category-story.php` (make sure the slug is 'story'). Put your code in this file. WordPress will automatically display the posts from `Story` category using this template. (More about category templates here). And yes, you can use widgets outside of the sidebar, read how.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, sidebar" }
Drop down menus css in custom menus I have created some pages and some pages have children.When i go to the wp admin menu,i create new menu and drag all the pages,including ones with children pages.I notice that the menus are all displayed without the cool drop downs i had hoped to see. Does it mean that menus created in the wp admin cannot have drop down menus?.
Dropdown menu is something that handles by CSS or javascript (in some case) So a your theme should take care of that not the wordpress engine. When you add a nested menu items on wordpress menu that means wordpress will output a specific html structure for that menu. <ul> <li></li> <li></li> <li> <ul class="sub-menu"> <li></li> <li></li> </ul> </li> </ul> So, your theme css will have to use appropiate css to handle the dropdown funcitonality. Hope it clear.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "menus" }
How do I do a page break? Is there a way to add a page break into length pages? Preferably automatically, but doesn't really matter. Ideally without a plugin.
You can insert the quicktag `<!--nextpage-->` into a post. Using `wp_link_pages()` you can generate the pagination links.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "posts, theme development, pages, content" }
Create a dropdown with Custom Post Types as option in admin I need to create a dropdown menu with " **posts** from a custom post type" as option. This dropdown will be placed as custom meta box. For example, I want all posts with the custom type "Video" as option in the select. <select> <option>post title n°1<option> <option>post title n°2<option> .... </select> Thanks
Here is the code I'm using in a project I'm working on. function generate_post_select($select_id, $post_type, $selected = 0) { $post_type_object = get_post_type_object($post_type); $label = $post_type_object->label; $posts = get_posts(array('post_type'=> $post_type, 'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1)); echo '<select name="'. $select_id .'" id="'.$select_id.'">'; echo '<option value = "" >All '.$label.' </option>'; foreach ($posts as $post) { echo '<option value="', $post->ID, '"', $selected == $post->ID ? ' selected="selected"' : '', '>', $post->post_title, '</option>'; } echo '</select>'; } `$select_id` is used as the name and id of the select, `$post_type` is the type you want to be made into the select and `$selected` is the post id you want selected in the select box.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "custom post types, admin" }
replacing the_autor or make callback I'm looking a way tho change the `the_author();` function in the loop, I have post meta data with the name of the user who posted. I need to do this: * If the user is registered, show `the_author();`, but if isn't show the data from the post meta. Since `the_author()`, function doesn't have a callback function I'm a little lost, maybe making a function? The idea is replace `the_author()` in my theme.
There is no need to change the `the_author()` function itself. A simple conditional tag will do the trick. Example: <?php /*** on your functions.php file ***/ function ifRegistered() { if(is_user_logged_in()) { the_author(); } else { echo get_the_post_meta($post->ID, 'your_post_meta_key', true); // or anything else, of course } } /*** on the template you want to use the function **/ // your HTML markup ... ifRegistered(); // more possible HTML ... ?> Hope that helps! EDIT: Updated the function.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "post meta, loop" }
Show TwentyEleven header image only on home page i am trying to remove the header from one page (actually all the pages exept the Home page) i did some research i found this code #post-xx .entry-title{display:none;} whereas the xx is the page ID . but it doesn t work for me do you know the exact code and exact place (and what s the page ID), or any other way... any help would be appreciated my website www.danielbelseamusic.com thanks a lot,daniel
To remove the header image of the Twenty Eleven theme on other pages then your homepage, change the following code in header.php (in wp-content/themes/twentyeleven) **Before:** <?php // Check to see if the header image has been removed $header_image = get_header_image(); if ( ! empty( $header_image ) ) : ?> **After:** <?php // Check to see if the header image has been removed $header_image = get_header_image(); if ( ! empty( $header_image ) && is_front_page() ) : ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "pages, headers" }
Can I use get_term_children to show child terms if they exist and show something else if they don't? I have a hierarchical custom taxonomy called taxon... In my taxonomy.php I am showing children of the current taxon, if you click one of those children you should be taken to a page showing all of that child taxon's products. Parent taxons never have products so its just a navigation structure. $term_id = $term->term_id; $taxonomyName = "taxons"; $term_taxons = get_term_children($term_id, $taxonomyName); if ($term_taxons != null) { ?> Show Child Taxons <?php } else { ?> SHOW PRODUCTS <?php } ?> This does not work. I have tried running the it like if $term_taxons == null then do something else something else and that doesn't work either...
if ( ! isset($term_taxons->errors)) { ?> Show Child Taxons <?php } else { ?> SHOW PRODUCTS <?php } ?> get_term_children returns a WP_error on failure.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy" }
Strip Paragraph Tag In my image.php I am using this code to grab the image caption of each image. The problem is a paragraph tag ( `<p>` ) is being added around it and I don't want one to be. Could somebody tell me how to strip this tag? <?php if ( !empty($post->post_excerpt) ) the_excerpt(); ?>
strip_tags — Strip HTML and PHP tags from a string if (!empty($post->post_excerpt)) { $excerpt_raw = strip_tags(get_the_excerpt()); echo $excerpt_raw; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php" }
Right way to include blog-header.php? I have a voting system on a custom post which uses AJAX, and I have a file that handles the AJAX request. This file is inside a sub folder named `php` of my theme. Hence the structure is: > ../wp-content/themes/my-theme/php/ajax-handler.php I use the following line to include the `blog-header.php` file: `include('../../../../wp-blog-header.php');` This works fine, but with debug mode on, I see warnings telling me that WP failed to open the stream as the file `blog-header.php` is non-existent. So I tried this: `define('WP_USE_THEMES', false);` `require('../../../../wp-blog-header.php');` Warnings gone, but $wpdb not recognized. Any ideas on how to make this work without the warnings?
The "right way" is to not include it at all and use WordPress provided means for AJAX in themes and plugins.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "ajax, wp blog header.php" }
TinyMCE is broken After switching hosting server, the tinyMCE in the post editing screen does not fire up. Here is the message of the console. !chrome console printout As you can see, wp-tinymce.php seems to fail. So far, I've tried : * chmoding 777 (just to be sure) all the js/tinymce content * reuploading the entire wp-include, forcing file replacement changing * the header from javascript to json (here are the 3 tries i did): try1: header('Content-Type: application/x-javascript; charset=UTF-8'); try2: header('Content-Type: application/json; charset=UTF-8'); try3: header('Content-type: application/json'); In Firefox 's firebug extension, the message is "illegal character" and when i open the file from within firebug, instead of seeing the code, all chars are messed up. But in my IDE, the php code looks correct. Any other idea? Would it be a server misconfiguration?
Solved it by adding this to wp-config.php, which kills the js combining. define( 'CONCATENATE_SCRIPTS', false );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "tinymce" }
Stripping wp_link_pages? I can't figure out for the life of me how to strip the following code of the `<p>` tag. Even adding the remove code for wpautop in my functions won't do it. <?php wp_link_pages('before=Pages'); ?>
Take a better look at the arguments that this functions accepts: wp_link_pages(array( 'before' => 'Pages', 'after' => '', ));
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "wp autop" }
How can I put a custom meta box above the editor but below the title section on the edit post page? I have a custom meta box for a custom post type that my client wants placed between the title/permalink section and the post editor in the admin panel. Is this possible and if so is there a hook/filter/etc that I would need to use?
* Simply add a meta box using the _advanced_ context, and _high_ priority * Then, latch on to the `edit_form_after_title` hook * Print your meta boxes out there, then remove it so it doesn't appear twice. // Move all "advanced" metaboxes above the default editor add_action('edit_form_after_title', function() { global $post, $wp_meta_boxes; do_meta_boxes(get_current_screen(), 'advanced', $post); unset($wp_meta_boxes[get_post_type($post)]['advanced']); });
stackexchange-wordpress
{ "answer_score": 57, "question_score": 36, "tags": "post editor, metabox" }
get_header('header2') not working properly in child themes I am trying to replace header-header2.php of my main theme in my child theme and by adding the file in the child theme, but wordpress is loading the file from the main theme itself. Is the second header not supported in a child theme??? In index.php, I am using get_header('header2') to call the file. Anyone knows how to do this. Please help, its urgent!!!
If you are using an index.php in your child theme why not use `get_header('child')` and use `header-child.php` to display the header.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "themes, child theme" }