question stringlengths 0 34.8k | answer stringlengths 0 28.3k | title stringlengths 7 150 | forum_tag stringclasses 12
values |
|---|---|---|---|
I created a childtheme: Fisio Inside I have: page-team.php with the name: <code> <?php /* Template Name: Page - Team */ ?> <?php get_header(); ?> <script>alert('its the team page')</script> </code> And in the wp-admin I selected it for the page: Team The problem is that any changes I make to pag... | You have created custom post type named team so it is displaying archive of custom post type team on the team page try changing slug of team page from team to team2 or something else but not team. Visit this page to learn more about how wordpress handles templates. | WP is not using the select custom template.php that its selected for a page | wordpress |
I'm using WordPress 3.5.1 and twentyten. I want to remove the support for custom background. I found this text: http://codex.wordpress.org/Function_Reference/remove_custom_background but i'm a newbie in php, so I dont know what to do whit the information. I guess I should use this code <code> <?php remove_custom_bac... | Inside the theme folder there should be a file called <code> functions.php </code> . Search for the line <code> add_theme_support( 'custom-background' ); </code> and replace it with <code> #add_theme_support( 'custom-background' ); </code> which is simply 'deleting' calling the function and thus the possibility to spec... | How to remove custom background? | wordpress |
So, I need to add a custom options page, and based on as many tutorials I could find, I came up with the following code to create an officers & chairs options page for my group, mainly, so I can write more advanced stuff for my site. The code is here: <code> add_action('admin_menu', 'composit_settings_page'); funct... | The problem part is this line: <code> <form method="post" action="options.php"> </code> This sends your form to wp-admin/options.php (and I guess you're not sending the form from this URL). Lave the action value empty <code> <form method="post" action=""> </code> And your form will send itself to the same p... | Wordpress Options Page not working | wordpress |
I'm working on a plugin in which I do the following for autoloading classes: <code> function TFSLAutoload($class) { $classfile = dirname(__FILE__).'/includes/'.strtolower($class).'.php'; include $classfile; } // function TFSLAutoload spl_autoload_register('TFSLAutoload'); </code> In the plugin (classes) I can instantia... | There is no built-in autoloader in WordPress. But other plugins or a theme might have registered an autoloader, and depending on the order of execution these are called earlier or later than yours. Update 21. 08. 2014 This answer is no longer what I would recommend. Do use an autoloader if you need one. The only way to... | Problems with autoloading classes via sp_autoload_register / maybe interfering WP-specific autoloader | wordpress |
get_posts('numberposts=5&category=93+85')get_posts('numberposts=5&category=9385') Is there a way to have get_posts grab only posts that are in BOTH categories, as above? | Use <code> WP_Query </code> 's <code> category__and </code> : <code> $args = array( 'posts_per_page' => 5, 'category__and' => array( 93, 85 ) ); $my_query = new WP_Query( $args ); while( $my_query->have_posts() ): $my_query->the_post(); the_title(); endwhile; wp_reset_postdata(); </code> | Get_Posts, only if in both categories | wordpress |
I've got my user registration to automatically create a post with the user_register hook however the title shows up as (no title) can someone help me with what I'm doing wrong here? <code> add_action('user_register','create_new_user_post'); $userinfo = get_userdata($user_id); $disname = $userinfo->display_name; func... | Your function <code> create_new_user_post() </code> can't see: <code> $userinfo = get_userdata($user_id); $disname = $userinfo->display_name; </code> Place those within the function so that the function has access to those variables. | Create a post with user_register doesn't create title | wordpress |
My site recently got hacked, and all my admin users lost their administrator level access. But when I access mySQL database, I saw all the users still exist. How can I create an administrator when I can access the database only? | Run this script in phpMyAdmin or whatever tool you use to access MySQL: <code> SET @user_login := 'justin_foell'; SET @user_pass := 'Q9xiHgzZ'; SET @user_email := 'justin@9seeds.com'; INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_email`, `user_registered`) VALUES (@user_login, MD5(@user_pass), @user_email, n... | Create a WordPress administrator without access to back-end | wordpress |
i have custom fields like this: "country" - values: "USA", "Russia", "China" "city" - values: "Chicago", "Moscow", "Beijing" I want when user in custom field "country" choose value "USA" after that in custom field "city" show only "chicago". Is it possible? And how can I do this? | This is possible by using AJAX. The following links are containing more information about AJAX and implementation in WordPress: http://codex.wordpress.org/AJAX Ajax (Asynchronous JavaScript And XML) is a technology that allows a web page to perform actions or update dynamically, without completely reloading http://code... | Custom fields: dropdown values depending on other custom field value | wordpress |
I'm developing a theme. I added the codes (below) into the <code> header.php </code> . But I posted it into the WP theme repository, and it's under review, and the reviewer informed me to enqueue the style with <code> wp_enqueue_style() </code> / <code> wp_enqueue_script() </code> . But can't understand how to implemen... | This is what you could do: 1 - Put de CSS in a separate file and save it in your theme directory. 2 - put the following code in your <code> functions php </code> : <code> function wpse_89494_enqueue_scripts() { if ( has_nav_menu( 'secondary' ) ) { wp_enqueue_style( 'wpse_89494_style_1', get_template_directory_uri() . '... | How to enqueue the style using wp_enqueue_style() | wordpress |
i want to hide subcategories in widget sidebar . just in widget sidebar i was added in style.css this code <code> .children { display:none;} </code> but this code do hide to the threaded comments what is the way to hide just sub categories in sidebar | You didn't give us markup so I can't know if this is correct but <code> .sidebar .children { display:none;} </code> EDIT: I think you're looking to hide your .commentlist .children correct? Line 1460-1463 of your file are the .children selector. try making each of them <code> ol.commentlist li ul.children li.depth-2 { ... | How to hide sub categories in sidebar | wordpress |
I am using wordpress gallery shortcode [gallery] I was wondering if there is anyway to paginate them without using a plugin. | I've written answer to stackexchange-url ("How to paginate attachments in a secondary query as gallery?"), which can be used for solving this problem. Like @wpmudev-ari said the [gallery] shortcode can be rewritten, or a new shortcode could be created. I explain below - B. - how this can be done. Additionally there is ... | How to paginate wordpress [gallery] shortcode? | wordpress |
My blog has been working fine for months. Today when I tried to open it I got the following errors: <code> Warning: require(/home/dhabitat/public_html/blog/wp-includes/functions.php) [function.require]: failed to open stream: Permission denied in /home/dhabitat/public_html/blog/wp-settings.php on line 69 Fatal error: r... | Check the permissions of the <code> functions.php </code> . This page in de Codex about changing file permissions explains a lot about wich permissions you have, or can use. On computer filesystems, different files and directories have permissions that specify who and what can read, write, modify and access them. This ... | Fatal error: require() [function.require]: Failed opening required in wordpress | wordpress |
I have this bit of code for displaying the value of links key of my custom fields. <code> $links = get_post_meta($post->ID, 'links', false); foreach($links as $link) echo '<div class="first-link bottom-dotted"><p><a href="">'.$link.'</p></div></a>'; </code> What I need to do is in... | I don't know if you can count on the order of both custom fields to be equal when returned from get_post_meta(), but if you can, you could use: <code> $links = get_post_meta($post->ID, 'links', false); $URLs = get_post_meta($post->ID, 'URLs', false); for ( $i = 0; $i < count( $links ); $i++ ) { if ( empty( $UR... | KEY and VALUE custom field issue | wordpress |
I am using the default Twenty Twelve Wordpress theme with my site, and I am trying to customize the sidebar. The CSS I am using is: <code> .widget-area, #secondary{ float: right; width: 210px; font-family: Georgia, "Times New Roman", Times, serif; padding: 0 15px 0 15px; border-bottom: 1px solid #cacaca; border-top: 1p... | You have added this CSS in below css3 media query and this css3 media rule does not support IE8 and below browsers so it is not applying css contained in its block. <code> /* Minimum width of 600 pixels. */ @media screen and (min-width: 800px) { .widget-area, #secondary{ float: right; width: 210px; font-family: Georgia... | IE 6~8 ignoring font, background, and margins on sidebar | wordpress |
I succeeded in getting both images and video to echo into a bootstrap carousel. However, I run into a problem when the post contains no images. If there are no images then there is no class="item active" so the bootstrap carousel won't show. Here is my workaround I feel like I'm almost there, can someone give me a hand... | You might try to replace the foreach( $myCarousel as $carousel ) with: <code> foreach($myCarousel as $carousel){ $myimg = get('projectdetails_image',1,$carousel); if ( !$myimg ) { // use this if you want to show a default image when no image is available in the post $myimg = get_template_directory_uri().'/images/defaul... | How to echo a different field if another field is empty? | wordpress |
I have a class with this function to provide a user language based on $user_id <code> function provide_user_language($user_id) { return apply_filters('get_user_language',$user_id); } </code> So in my script, I can simply get the user language by doing this: <code> $user_language=$this->provide_user_language($user_id... | Thanks Tom, Unfortunately Toscho concept didn't work for me, so I dig deeper in the add filter documentation here: http://codex.wordpress.org/Function_Reference/add_filter and they allow anonymous functions as callback. This method finally solved my problem. This is how I resolve this one for other users that are exper... | How to pass a parameter to this add_filter example | wordpress |
I am seeing many plugins use the following format for defining their constant: <code> /* Set the constant path to the plugin's javascript directory. */ if( !defined( 'MY_ETS_JS' ) ) define( 'MY_ETS_JS', MY_ETS_URI . trailingslashit( 'js' ), true ); </code> So basically there is a check before we define the constant. My... | These are not PHP global variables , they are constants that cannot be modified(hence the name). Trying to redefine them, using a <code> define() </code> will trigger a notice since they are already defined(and consequently keep the initial value assigned). To stay away from notices, you should check if they have been ... | Checking for existence of constants before defining them | wordpress |
I want to display, based on the current page another header image. Short example: Home -> Image A PageId 1,2,3,4 -> Image B (2,3,4 are childs of page 1) PageId 5, 6 -> Image C ... I tried to edit the header.php of my theme, because there is the coding block which displays the header image: <code> <?php // The header... | On the <code> else if </code> there is missing a closing bracket: <code> } elseif ( is_page(1) ) { </code> . Since all you alter is the file name, it's sufficient to use the following code: <code> if ( is_home() ) $my_header_image = get_header_image(); elseif ( is_page(1) ) $my_header_image = "http://.../ImageB.png"; e... | Display different header images based on current page | wordpress |
I've been googling this for a while, and came across this link here: stackexchange-url ("Can I limit this meta box to a particular page?") What I am trying to achieve is adding a custom Meta Boxe I created onto a CPT Posts Screen ( <code> edit.php?post_type=custom </code> ). What I tried to use is this: <code> add_acti... | From your comment, it sounds like you don't want a metabox. A metabox is used to add metadata to a particular post, not create a new post from scratch. What it sounds like you want to do is create a widget to do what you want and then invoke it through an action or filter at the top/bottom of the page. You can use the ... | Possible to add meta box to edit.php pages? | wordpress |
I have a new, custom theme that I've uploaded on a pre-existing site/blog. Everything seems to be working ok, with the exception of the older blog posts not showing up. Any ideas what I can do to fix? <code> <?php get_header();?> <div id="blog-container"> <?php get_sidebar( 'blog');?> <div class="c... | What posts exactly are not shown? In your code there are no page links (pagination). Could it be that you just see the the number of posts according to the respective admin setting? In addition, I just have been learned NOT to use <code> query_posts </code> . Why would you use it there anyway? Assuming, this is a post-... | older blog posts not showing in new theme | wordpress |
Is there way to extract embedded video without using a regular expression as seen here ? I was hoping that there would be a way to get them using a WordPress function. | It looks like the closest you get is in the WP-Embed class: <code> autoembed( $content ); </code> It says it extracts urls which are on distinct lines (like you'd put a url in for embedding it), but it then passes it to WP_Embed::shortcode(). Not quite what you want. You could dig into WP_Embed::shortcode() to see if y... | Built-in Method to Extract Embedded Video from Content | wordpress |
Is it possible to hide plugins on a per blog basis in WordPress multisite? I would like not to have plugins available on certain blogs. | Super Admin is your friend! If a plugin is not active in the Super Admin (also lamely named Network Admin) Then it won't show up as an option for individual blogs. It basically works like this: Installed as Super Admin (main site) and "Network Active" will be active on all blogs on the network. Installed on Super Admin... | Multisite plugin hiding on specific blogs | wordpress |
I have a plugin that will send tutorial emails to our users. These tutorials are created in wordpress and stored in wp_posts table in the database. Of course I could simply run a query to get the post and that's it. But is there a special built-in function that I can use to get the post content after Wordpress post pro... | If by "post processing" you mean the autoformatting, the shortcode processing, that sort of thing, then you want to pass the content through the <code> the_content </code> filters. <code> $my_id = 7; $post_id_7 = get_post($my_id); $post_content = $post_id_7->post_content; $post_content = apply_filters('the_content',... | How to get the post content after Wordpress post processing? | wordpress |
I don't know why but it seems like wordpress is adding a second backslash when I'm using the following functions: <code> addslashes($str_with_single_quotes) addslashes(stripslashes($str_with_single_quotes)); esc_sql($str_with_single_quotes) str_replace("'", "/'", $str_with_single_quotes) </code> What I'm doing is that ... | In your code json_encode() function causes to add second backslash on the following line. <code> $data = json_encode($item_data); </code> Add the following code in place of above code so it will replace double backslashes with single backslash in data returned by json_encode function. <code> $data = str_replace("\\'","... | wordpress is adding a second backslash when I use addslashes | wordpress |
I am generating posts based on rows from a table on an existing database. If a row in the database gets updated I will have to update the respective post. The proble is that I have to find the post to be able to update it, and I don't have any suitable key for that... One chance would be using the title, but the title ... | Concept As I've currently done this, I found the easiest part would be to save the original UID (unique ID) from your "origin"-database as post meta value. Every time you update a post, you just have to search for a post that has this meta entry. Just make sure that you set the last value to <code> true </code> when yo... | How to store an extra (surrogate) ID when creating a post with wp_insert_post? | wordpress |
I'm trying to adapt some code on calling a custom template via rewrite rule . I have a custom taxonomy called "state". I want to create an archive for the taxonomy, that lists all the terms in that taxonomy. <code> http://www.site.com/state </code> Would load my custom template where I can query the terms and loop thro... | I needed a better rewrite rule for proper pagination. <code> function kia_custom_rewrite() { // registers the state_var query variable add_rewrite_tag('%state_var%','([^&]+)'); // handles site.com/state and pagination such as site.com/state/page/2 add_rewrite_rule( 'state(/page/([0-9]+)?)?/?$', 'index.php?state_var... | Redirect taxonomy to custom template to list terms in taxonomy | wordpress |
I have created WP theme for property company, with custom post types which are actually apartments so users can from one custom page enter all the informations and the custom post gets saved. I would like to now display custom pages for "My account" and "Edit apartments" options. So is there a way to do a custom my acc... | So Wp User Frontend Plugin works for displaying Profile page, and Edit post page for registered users on site. Plugin lets you create "Dashobard page" where users can see all of their published posts and have Edit option for each of them. You can also Add new fields on your forms, and then display "Edit page" or "Add n... | Custom My account page and custom page for editing posts | wordpress |
I'm in the process of customizing dp-error.php. I'm using the mail() function to alert me when there's a database connection problem on my website. The trouble is, what if 1000 people visit my website when it's down? Wouldn't I get 1000 emails? Here's the code I'm using to send email: <code> mail("email@email.com", "Da... | I'm not sure that this is a good idea, email is just not a good medium for emergency messages (who will see the email when you are a sleep or at the beach?), and if you want to monitor the site it is better done by external service which will probably be able to send you an SMS or make a phone call. That being said, if... | How can I restrict php mail() to only send me one email after a db error | wordpress |
I installed the word press on my vm and configure my port 8000. Now, when I am trying to login into wordpress using <code> http://localhost:8000/wordpress/ </code> on browser , the link is getting changing into <code> http://localhost/wordpress/ </code> and displaying "Problem loading page : Unable to connect". I have ... | Check the 'siteurl' and 'home' values in your wp_options table, and update those URLs to: <code> http://localhost:8000/wordpress </code> | wordpress local host web login not working after port configuration | wordpress |
What is the best way to do this: <code> <?php wp_nav_menu( array('menu'=>'Primary', 'container'=>'', 'items_wrap'=>'<ul id="%1$s" class="%2$s">%3$s<li>'.get_search_form().'</li></ul>') ); ?> </code> | You can add any item you want to a menu by filtering <code> wp_nav_menu_items </code> . From the tutorial How to Add a Search to Menu , this is how you'd add a search form: <code> add_filter('wp_nav_menu_items','add_search_box', 10, 2); function add_search_box($items, $args) { $searchform = get_search_form( false ); $i... | Search form as list item in menu? | wordpress |
I have a page template and on the page I have a loop such as: <code> query_posts('post_type=post&posts_per_page=5&paged='.get_query_var('paged')); if(have_posts()){ while(have_posts()){ the_post(); the_title(); } } </code> The problem is that no posts are coming back when there should be about 5 or 6. Is there ... | Firstly, use <code> WP_query </code> instead of <code> query_posts </code> : Secondly, for (static) pages use the variable 'page' (not 'paged'). <code> $my_query = new WP_query( 'post_type=post&posts_per_page=5&paged=' .get_query_var('page') ); if ( $my_query->have_posts() ) while( $my_query->have_posts()... | Loop not showing up on page template | wordpress |
<code> <?php $args = array( 'cat' => '2', ); ?> </code> <code> <?php wp_get_archives($args); ?> </code> I pull out the custom category with the above codes, it works fine & shows up "February 2013". here, My question is can I display it in "weekly". I put (type = weekly) in $args . but it displays we... | I read the readme.txt file of Archives for a category WordPress plugin . The plugin author has stated following limitation on it. Limitations This plugin does not work for weekly archives. The list with archive links is correct, but the links themselves do not include the category. So when used, WordPress will not filt... | weekly archive for custom category | wordpress |
I am using meteor-slides plugin to make header as a slideshow. I am using twenty-eleven theme. Now i need to make this slideshow for my homepage only and featured images of other pages as headers for the respective pages. Can anyone help me with this? | I have got answer for it. I have changed the code to add meteor slides plugin in functions.php to show the slideshow just in the homepage. <code> <?php if ( is_front_page() ) { if ( function_exists( 'meteor_slideshow' ) ) { meteor_slideshow(); } } ?> </code> After that i used a plug called WP display header to se... | Meteor Slides as header only for homepage and Use featured image of each page as header for respective pages | wordpress |
So I should probably mention up front that I'm developing a plugin so my url is 'mysite.com/plugin' (Just in case this is related to my issue. So, In my main plugin file (myplugin.php) I have added the following: <code> $plugin_url = plugins_url('/my-plugin-directory/'); </code> immediately followed by <code> wp_enqueu... | This is a PHP issue, not specific to WordPress. I suggest reading the PHP documentation on variable scope to understand why this doesn't work. There is no <code> $plugin_url </code> variable defined within the scope of your <code> my_jquery_enqueue </code> function, you would have to call <code> global $plugin_url; </c... | plugins_url() works everywhere but wp_reqister_script() | wordpress |
Is there a function in WordPress that will check if the page you are on is a sub-category archive page? Like the way is_category checks if it's a category page? | Sub-categories use the regular category archive page by default. There is no function such as is_subcategory. But you can write your own. Here is an example: This will check if the current page is a sub-category. Or if you pass an ID it will check if the ID is a subcategory. <code> function is_subcategory( $cat_id = NU... | Wordpress function like is_category for subcategory? is_subcategory? | wordpress |
live blog I've just implemented a new, custom theme. I've noticed that my posts are now displaying all on top of one another and I can't figure out why. To test my code, I swapped out my custom loop for the plain Wordpress loop- the problem persisted. I've also disabled every single plugin and again, problem persists. ... | You have closed div having content class inside if statement which causes to break nested markup, instead close it outside if statement as following. <code> <?php /* Template Name: Blog */ ?> <?php get_header();?> <div id="blog-container"> <div class="content"> <?php get_sidebar( 'blog');?>... | new custom theme - posts displaying on top of one another | wordpress |
I'm using the query below in the index.php file as the main query, whenever I try to go to the 2nd page I get a 404 error, I tried using posts_per_page but to no avail. <code> <?php $args = array( 'post_type' => array( 'post', 'videos', 'music' ), 'tax_query' => array( array( 'taxonomy' => 'content', 'field... | Pagination in URLs only works for the "main" query. What you've created is a secondary query, so WordPress doesn't "know" about it in such a way that the application would be able to create pagination. If you use a secondary query (like your example) it's up to you to do the pagination stuff manually. Rather than creat... | Trouble Making WP_Query paged | wordpress |
wondering if anyone could explain why the author used ob_start() and ob_clean() in this code to build an import/export page in WordPress? Since I'd like to integrate this code into another plugin, and I want to separate the code into different files, where would I need to place ob_start() for this to work? <code> <?... | you should read HERE or stackexchange-url ("HERE") , stackexchange-url ("HERE") (and lots of other places ) more about output buffering . If you output some html or javascript code or use echo or print within php, this information is being sent DIRECTLY to the browser in chuncks as the PHP script is processing through ... | Why is output buffering used here? | wordpress |
For our 'Posts' type, our Contributors can see only their own posts, which is what we want. But for our custom post types, Contributors can see every post, including drafts. Is there a way to limit their view of custom posts so they only see their own posts like it is in the 'Posts' type? Edit: Maybe I wasn't as clear ... | You need to use the action hook <code> pre_get_posts </code> . See the comments for details and modify the Custom Post Type(s) to your own: <code> add_action( 'pre_get_posts', 'filter_cpt_listing_by_author_wpse_89233' ); function filter_cpt_listing_by_author_wpse_89233( $wp_query_obj ) { // Front end, do nothing if( !i... | Restrict Contributors to view only their own custom post types? | wordpress |
We're using the disqus plugin on our wordpress site, so anyone commenting should have a login through disqus. Yet, I'm still seeing spammers trying to post through the regular comments API. They're not getting through to the post, but they're clogging my inbox as admin. How do I disable this API - I only want to accept... | There is much easier way to close standard WordPress comments. Just add <code> add_filter( 'comments_open', '__return_false' ); </code> to your <code> functions.php </code> file and comments will be closed. | Disable wordpress comments API | wordpress |
The Back-end of Wordpress is nice, but I would like to customize the UI to some degree. My goal is to make the user experience REALLY simple for untrained users. I suspect plugins exist for this, but I thought I would ask the experts of Stack Exchange, before chasing any ideas down potentially deep rabbit holes. So, wh... | You will need an Admin Theme. Despite its name, this should be implemented as a plugin. Here is a basic plugin file: <code> <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Admin Theme */ add_action( 'admin_init', 't5_admin_theme_init', 11 ); function t5_admin_theme_init() { $settings = new stdClass; $settings-&g... | Back End Interface Plugin | wordpress |
I want it to be possible for the users to edit and delete their own posts, not only through the admin panel as it is by default. I've look around on the net but haven't found any information about it. How can this be done? | Take a look at http://wordpress.org/extend/plugins/front-end-editor/ If you assign users the Contributor role, they'll be able edit their own posts from the frontend. You could use a basic redirect to prevent Contributors from being shown the admin panel on login... look around StackExchange/Google for several solution... | Edit / delete custom post types through web page (not admin) | wordpress |
I've created a unique single post template to give people the option of reading all posts of a certain category using the awesome "reveal.js" which they access via this link <code> <a href="?show=presentation/">presentation</a> </code> The problem is the ugly URLs, which end up looking like <code> website.c... | You can achieve this via the Rewrite API 's <code> add_rewrite_endpoint </code> : <code> function wpa89344_add_presentation_endpoint(){ add_rewrite_endpoint( 'presentation', EP_PERMALINK ); } add_action('init', 'wpa89344_add_presentation_endpoint'); </code> Then in your template or wherever you differentiate a presenta... | changing permalink for custom template in posts of a certain category | wordpress |
I have a shortcode for a blockquote <code> [blockquote]this is the quote[/blockquote] </code> ... this is the code. <code> function shortcode_shortcodetest( $atts, $content = null ) { $return = '<div class="blockquotewrapper"><blockquote>'; $return .= do_shortcode( $content ); $return .= '</blockquote>... | By chance I just happened to discover what it was, so I think I'll leave this here as it might help someone in the future. Some web pages, including an answer to stackexchange-url ("this question") suggest using the following code to prevent wpautop from running until after the shortcodes. Now I wasn't able to fully un... | What is wrong with this code I have to make a blockquote shortcode | wordpress |
For example, I have a link on my site like /tag/green and select content from all posts tagged green are shown using a file loop-tag.php which is about as simple as <code> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- Here I grab the image from the post with that tag --> <?php ... | Because it must be set in back end of your wordpress site. You can check and change it from <code> Blog pages show at most </code> field from settings => Reading pages menu. As shown in below screenshot. It will change the setting for all pages , but if you want to make this change only for tag page then in your case y... | Why am I being limited to ten posts on a custom loop? | wordpress |
The main problem here is about too large file size of image not image re-sizing My wordpress website is like a web gallery which contains many images. Initially, I just uploaded hundreds of images via wordpress media uploader without caring of its file size at all. However, when i browse my website, it's too slow to lo... | It is possible to re-size images on the fly if you are comfortable programming in PHP. Judging from your question, I expect that your not there yet. If that is the case, you should check out the Regenerate Thumbnails plugin. With this plugin, you can change the images sizes you want in the media settings page and then ... | Is it possible to reduce image filesize on the fly (when users enter my website)? | wordpress |
I want to increase the maximum upload file (media default:32mb). Before posting i search, but i didn't have the result that i want. My host didn't support .htaccess. I create my own <code> php.ini </code> with these: <code> memory_limit = 32M upload_max_filesize = 120M upload_max_filesize = 120M post_max_size = 100M fi... | Please try to upload the php.ini file to the document root directory or to the same directory as wp-config.php. You may also want to modify memory_limit to 120M and modify max_execution_time to 300. | increase maximum upload file | wordpress |
My theme already has a specific body class filter for the colorscheme it uses. How can I also add a body class filter for the page name? Basically I want to combine these statements: <code> <body <?php body_class(); ?>> <body class="<?php echo get_stencil(); ?>"> </code> I've been trying but I j... | directly in the body tag line: <code> <body <?php body_class( get_stencil() ); ?>> </code> http://codex.wordpress.org/Function_Reference/body_class#Adding_More_Classes | How to combine multiple body classes | wordpress |
I am having issues with the get_the_terms php that is pulling in my current posts categories (custom taxonomy portfolio_category). I can successfully pull in the last category. If you look at this page you'll see links along the top: http://www.slarc.com/portfolio-view/central-control-building-east-texas/ those links a... | You need to include your html inside the foreach, something like this: <code> $url = site_url(); foreach ( $terms as $term ) { $linklist .= "<h3 id='Proj_Categories'><a href='" . $url . "/projects/" . $term->slug . "'>" . $term->name . "</a></h3>\n"; } echo "<ul>" . $linklist . "<... | Pull in taxonomy links using get_the_terms? | wordpress |
I want to setup a page that will display different content for each registered user of my site who falls within a specially-created user role ('map_user'). So, for example, if a site user who is in the 'map_user' category logs into the site they're automatically forwarded to a specific page. This page then refers to th... | Try to do this: <code> <?php global $current_user;?> <?php if(is_user_logged_in()) :?> <?php get_currentuserinfo();?> <?php if(is_array( $current_user->roles ) && in_array( 'map_user', $current_user->roles ) ) : ?> <div id="mapContent"> <?php require("/mapping/".$current_u... | How can I call a specific file (via php) by referencing the logged-in username? | wordpress |
I have this js function (the <code> textualizer.js </code> is external) but I can't make it works on WordPress. Any help? I already added <code> wp_register_script( 'textualizer', WP_THEME_URL . '/assets/js/textualizer.js'); wp_enqueue_script( 'textualizer' ); </code> to theme functions. What am I doing wrong? I know i... | Using Google with the error message you posted in your comment, Google show me this: The Deferred object, introduced in jQuery 1.5 Your source code says, that you use jQuery 1.4.4 . jQuery is bundled with WordPress and it's version is 1.8.3 . Please use the bundled jQuery and not one from an CDN. | Help to enqueue a js functions ( jquery) | wordpress |
I want one image in header.php to change for different pages. The function in header.php looks like that: <code> if(is_archive()): //change image to "Archives" endif; if(is_404()): //change image to "404" endif; </code> Now, is it possible to check if page is the search page AND what's the search string AND how many po... | Now, is it possible to check if page is the search page <code> is_search() </code> AND what's the search string <code> is_search() AND print get_query_var( 's' ) </code> AND how many posts were found? <code> is_search() AND print $GLOBALS['wp_query']->number_posts() </code> … or if you got a custom query&hell... | Get search.php results in header.php? | wordpress |
How do I use a custom theme, rather than the themes included with this plugin? Here is the link to the plugin: http://wordpress.org/extend/plugins/wp-maintenance-mode/ I see that under the plugin's settings there is a way to choose "own style" theme and a way to link to custom stylesheet, but I want to use my own html ... | How to do this is on the front of the plugins wordpress.org page. http://wordpress.org/extend/plugins/wp-maintenance-mode/ You can add your own html and stylesheet and add the url of this style to the options of the plugin. Write your style to this markup and upload to the webspace; after add the url include http:// to... | How do I use a custom theme for the WP Maintenance Mode plugin? | wordpress |
I'm noticing that adding a gallery to a page now just lists the ID's of images, slightly different to before, and reordering the images just amends the order of the ID's listed in the gallery short-code. So this... <code> [gallery order="DESC" link="file" columns="4"] </code> It's now this... <code> [gallery ids="3439,... | I had the same issue and was previously using <code> get_children() </code> to retrieve the top 4 images from a gallery for a given page. Here's the solution I came up with: <code> // helper function to return first regex match function get_match( $regex, $content ) { preg_match($regex, $content, $matches); return $mat... | Wordpress 3.5 grab first image from gallery | wordpress |
I am displaying related posts with the below code: <code> <div class="my-related-posts"><h4>You may also be interested in...</h4><ul class="relatedposts"> <?php $posts = get_posts('numberposts=4&orderby=rand&category='. $category->term_id . '&exclude=' . $current_post); foreach... | if there are no 4 related posts, the code below will fill the number with random posts of random categories, and avoid duplicates: <code> <div class="my-related-posts"><h4>You may also be interested in...</h4><ul class="relatedposts"> <?php $duplicates = array( $current_post ); $posts = get_p... | Selecting related posts | wordpress |
I've hidden and created various profile fields using the following code: <code> function my_user_contactmethods($user_contactmethods) { // You can get rid of ones you don't want unset($user_contactmethods['jabber']); unset($user_contactmethods['yim']); unset($user_contactmethods['aim']); unset($user_contactmethods['goo... | Try instead <code> $user_contactmethods['work'] = __('I work for...'); </code> and <code> <?php echo get_user_meta($current_user->ID,'work',true);?> </code> where the array index is <code> 'work' </code> instead of <code> 'I work for...' </code> , i.e. lowercase and without any spaces. | Calling custom profile fields? | wordpress |
I have used this with "echo" as its outside the loop i believe to the author of the post as a link, however its not displaying as a link? <code> <h2 class="sidebarheaders">Random Posts By You </h2> <br/> <?php $args = array( 'numberposts' => 5, 'orderby' => 'date' ); $rand_posts = get_posts( ... | You have to use <code> setup_postdata </code> function if you want to use <code> the_author_link </code> with custom loop. Do it like this: <code> <h2 class="sidebarheaders">Random Posts By You </h2> <br/> <?php $rand_posts = get_posts( array( 'numberposts' => 5, 'orderby' => 'date' ) ); fore... | Author Link Not Displaying | wordpress |
I am using contact form 7 to send an email form. I receive them, but my clients' email addresses - one at the host and one at gmail, never do. They claim that none of the messages end up in their spam folders either. The client did ask the host to take a look and they also claimed that there is no blocking of the form ... | I have had tons of issues with the plugin Contact Form 7 in the last couple months. Especially with Wordpress 3.5.1. I started using Formidable Pro for all of my clients in the last couple weeks. It costs a bit of money for the developer license, but the peace of mind that it is working and there is plenty support as w... | Contact Form 7 Plugin emails not being received by some accounts | wordpress |
For a single custom post type, I'm using previous_post_link and next_post_link with simple arrows. (Although text arrows are shown here, in the actual I'm using graphics with the text hidden via CSS.) Code: <code> <nav class="arrowNav"> <div class="nav-previous"> <?php previous_post_link('%link', '«'); ?... | Add following custom functions in functions.php file and instead of calling previous_post_link and next_post_link functions call custom_next_post_link and custom_previous_post_link custom functions respectively. <code> function custom_adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', ... | Using previous_post_link and next_post_link to wrap around post sequence | wordpress |
I am using the Settings API for a plugin's settings page. One of the settings allows the user to change the cron job interval for the cron job created by this plugin. Therefore I'd like to run a function on saving of the settings page, which checks the value in the database and compares it to the value the existing cro... | I'm not familiar with wordpress settings api but I know those options generated by settings api are handled/saved in wp-admin/options.php Unfortunately, <code> if ( isset( $_POST[ $option ] ) ) { $value = $_POST[ $option ]; if ( ! is_array( $value ) ) $value = trim( $value ); $value = stripslashes_deep( $value ); } upd... | Run function on settings save | wordpress |
Hi~ I'm back again and I'm trying to add another function to the script I was working on stackexchange-url ("a plugin that notify my friends of new post that mentions(@) them"). Now I want to change the plain text of my friends' names that I mentioned into links to their own wordpress blog address (if they have) once I... | You generally use <code> add_filter </code> before displaying information. For your case you can use <code> add_action('publish_post', 'your_function') </code> and then you intercept <code> $_POST </code> values. The content of the WYSIWYG editor is available through <code> $_POST['content'] </code> . The hook is of ty... | How to modify post content before writing to database? | wordpress |
I recently wanted to add a comfortable way to automatically add users to a page within small boxes including information an an image. So I followed this tutorial an customized the code: http://www.wpbeginner.com/wp-tutorials/how-to-display-an-author-list-with-avatars-in-wordpress-contributors-page/ On the active page, ... | It's because the TwentyTwelve theme has "clear: both;" set on H3 tags, which messes up the layout. Try adding this CSS: <code> #authorlist h3 { clear: none !important; } </code> | Inline-Table under TwentyTwelve not working | wordpress |
We have a few different websites running various versions of Wordpress that have comments and trackbacks turned off, yet I still receive emails saying there's some waiting for me! I've turned them both off in the admin area and also removed the comments box completely yet I still get them, how can I fully turn them off... | To prevent comments receiving add following line to your <code> functions.php </code> file: <code> add_filter( 'comments_open', '__return_false' ); </code> And to prevent trackbacks receiving just add this snippet: <code> add_filter( 'pings_open', '__return_false' ); </code> | Turning off trackbacks & comments | wordpress |
UPDATE: My original question has been solved, but this is turning into a valid discussion about why not to use global variables, so I am updating the question to reflect that. The solution was <code> <?php global $category_link_prop; echo esc_url( $category_link_prop ); ?> </code> as @TomJNowell suggested. UPDATE... | While I strongly advise against this, and it will not speed things up, your usage is incorrect. When you try to use a global you must specify the global keyword first. You have specified it here when defining its value, but outside of that scope it needs to be redeclared as a global scope variable. e.g. in functions.ph... | How to set and use global variables? Or why not to use them at all | wordpress |
I've tried searching for the problem here and also went through the trouble deactivating one plugin after the other. I still can't figure out what's going on, so maybe somebody here has an idea? Suddenly I get a Javascript error: It's caused by Jetpack's Hovercards. I suppose that in a recent Jetpack update they change... | You are loading jQuery 1.6.3. <code> .on </code> was included in jQuery 1.7 (I believe). jQuery itself is up to 1.9. You need to be using a more recent version of that library-- basically, just let WordPress load its own version and you should be fine. It looks like most of your scripts are loading from your domain exc... | Gravatar Hovercards (Jetpack) jQuery error | wordpress |
I am working on a wordpress site where I have created a directory page(authors.php) that lists all users and certain author meta. It works fine however I am trying to figure out how to only show users that have the required author meta filled out. I've tried many different things but have not been able to achieve what ... | You're probably better off to use <code> get_users </code> which returns an array of <code> <?php // get all users, regardless of roll. If you do need to restrict by // role you can use the `role` argument: get_users(array('role' => 'author')); $uses = get_users(array('orderby' => 'nicename')); foreach ($users... | Select From wpdb - Author/User Directory page | wordpress |
I've read a lot about redirecting and also checked out previous questions here, but NONE could answer my question. I think the problem is that I just don't understand the difference between the different redirection methods and thus don't know which one to choose in my situation and how to implement it. I'm really sorr... | First, make sure that Rewrites are enabled for your server, then add this to your .htaccess file in WordPress's root directory... <code> RewriteRule your-old-page-permalink/ http://www.yoursite.com/your/new/permalink/ [R=301,L] </code> This is a greedy match, so <code> your-old-page-permalink/ </code> just needs to cor... | How to redirect just one or two blog posts correctly? | wordpress |
We currently have a setup where anyone can register as a user and their own 'page' gets created manually by admin. We need a menu option to be something like 'View Your Page' and direct a user to their own page. I can't get my head around it as there is no current link between the user and the page that's created manua... | I've answered a stackexchange-url ("similar Question") and the same code can be adapted for this case. This creates a Meta Box where you can assign a user to a specific post/page, and the information is stored as a Custom Field. The following can be put in <code> functions.php </code> or in a functionality plugin (see:... | Associate Page with User | wordpress |
I posted earlier about changing my site's CSS based on user-choice from a drop-down and storing it in a cookie, which I think I have now resolved, and sort-of have working at the following address http://somethingoriginal.net . However I am trying to change the header image alongside the theme and it is proving much mo... | I had to take information from both of your posts to be able to come with something. Try replacing <code> <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" /> </code> width <code> <?php if (!(isset($_POST["styles... | Changing 2011 theme header image based on user dropdown | wordpress |
I'm want to get posts from the last 30days in a sidebar but I don't want to use query_posts, is there a way to achieve this with the get posts function? | Yes, simple add a filter before you call it and remove it after you do <code> function filter_where_wpa89154($where = '') { //posts in the last 30 days $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where_wpa89154'); $args = array( 'pos... | WordPress get posts by date without query_posts | wordpress |
Is it possible to make shortcodes available in the Author bio textarea? | It a matter of using <code> do_shortcode </code> in your <code> author.php </code> template file (or wherever applies). This function has to be " <code> echo </code> ed". And instead of using <code> the_author_meta </code> (which <code> echo </code> 's the result), use <code> get_the_author_meta </code> . <code> <?p... | Allow shortcode in the author bio textarea | wordpress |
I'm looking for a way to hide certain widgets from specific user types in the admin, Appearance > Widgets page? For instance, admins can see all widgets, but authors can only see a select few? I noticed there was a Code Canyon plugin, but it requires a framework with it also which I am not using. | You have to check for Roles and Capabilities in the action hook <code> widgets_init </code> and proceed accordingly. <code> add_action( 'widgets_init', 'remove_widgets_wpse_89138' , 15 ); function remove_widgets_wpse_89138() { // http://codex.wordpress.org/Function_Reference/is_admin if( !is_admin() ) return; // Grab c... | Hide certain widgets from specific user roles in admin | wordpress |
Using WAMPSERVER for windows 7, smartgit and Safe Search Replace I have pulled a wordpress code from my git, downloaded a database and inserted into my localhost's phpmyadmin. My home page works but when I click on one of the links I get the WAMP homepage. What am I doing wrong? I have tried the following in WP-Config ... | Ok, based on that, I'm almost positive that you need to re-enable permalinks for your site. You are probably missing your .htaccess file or it is missing WordPress's rewrite rules. Go to your admin and find Settings > Permalinks. Select an option, and click "Save Changes" twice (there is a quirk that this avoids). This... | Why do I get a WAMP homepage when clicking on specific website's URL on LocalHost? | wordpress |
I may be going about this all wrong but I'm trying to use get terms to get all of the terms that exist in every taxonomy. I think this might be a php question. get_terms allows you to specify which taxonomies it gets terms from in array like this... <code> get_terms( array(post_tag, category, nav_menu, link_category, p... | Ok, so I don't know what I was doing wrong because I tried this before and couldn't get it to work but I ended up using <code> array_values() </code> after a couple of people recommended it in another thread. I finally ended up writing it like this: <code> get_terms( array_values((get_taxonomies('','names'))) , $args )... | get a simple array of all of the term names that exist in all taxonomies | wordpress |
Why is the filter removed after fetching feeds in the following example (from WordPress.org?) <code> <?php function return_7200( $seconds ) { // change the default feed cache recreation period to 2 hours return 7200; } add_filter( 'wp_feed_cache_transient_lifetime' , 'return_7200' ); $feed = fetch_feed( $feed_url );... | The filter is added before the call to <code> fetch_feed </code> , then immediately removed so only that particular feed is given a different feed cache transient lifetime. Any other <code> fetch_feed </code> calls within the lifetime of the request won't have that filter applied, so will be given whatever the default ... | Usage of filters | wordpress |
I need to list posts in a very specific order that has nothing to do with the date of the posts or the title, or anything WordPress can figure out for me. I need this order to be used when I list posts in a category and on the category archive page itself. Is it possible to do something like this, were $idlist was an a... | First off, <code> query_posts </code> is terrible doesn't use it. It does all kinds of fun things like mess up the very useful conditional tags like <code> is_singular </code> and the like as well as mess up pagination. Short of hooking into the <code> posts_orderby </code> filter and writing some custom order by SQL, ... | How to order posts in an arbitrary order? | wordpress |
Inside of my loop in single.php, I used a custom query using <code> get_posts </code> to return posts belonging to a certain category. <code> <?php global $post; $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; $myposts = get_posts("paged=$paged&category=5");?> <?php foreach($myposts as $p... | You need to call <code> wp_reset_postdata() </code> after your query to restore the global <code> $post </code> variable that the navigation link functions use to determine the next/previous posts. | Using query_posts inside single.php loop | wordpress |
I am trying to create a simple function that adds or edits data in the <code> <html> </code> . Basically, before the server response is sent, I want to find where this piece of html is written at the top level of the page <code> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"> </cod... | If you can't edit your header.php, or would prefer not to, most decent WordPress themes should have (and certainly any that pass theme review to be in the official repository) <code> <html <?php language_attributes();?> > </code> in the opening html tag in the header.php template. There is a filter in the <... | Can't find where to modify attrbitutes | wordpress |
I am authoring a WP plugin, and I have to generate some JS (jQuery) code in "realtime". It is working fine in general, though I've stuck with one problem with the WP 3.5.1 and its default Twenty Twelve theme: there the scripts are inserted in the footer of the page, not in the header, causing my code to throw errors. I... | By default when you use <code> wp_enqueue_script </code> the script is inserted into the <code> <head> </code> section. This is usually set in <code> functions.php </code> . The argument also has a footer option called <code> $in_footer </code> , if you set this to true, the scripts will instead be added to the f... | Javascript block in Twenty Twelve theme | wordpress |
I want to render a menu with a container like this: <code> <nav class="nav"> </code> However, the container is just rendering with the default class name applied which I don't want. <code> <nav class="menu-main-nav-container"> </code> I can't understand where I'm going wrong. Here's my code: <code> if ( has... | You should use <code> 'container_class' => 'nav', </code> instead of <code> 'container-class' => 'nav', </code> You can check out the parameters here: http://codex.wordpress.org/Function_Reference/wp_nav_menu | Container class not appearing on navigation menu | wordpress |
I want to query 6 posts, but only those which have a featured image attached. I am using <code> meta_key </code> method for this with <code> WP_Query </code> as such: <code> $args = array( 'post_type' => 'post', 'meta_key' => '_thumbnail_id', 'post_count' => 6 ); $query = new WP_Query($args); </code> Followed ... | When running the importer, you must check the checkbox to download and import all media/attachments. If you do not, the posts will still have a featured image set, but the attachment they refer to will be invalid, and any attempt to call <code> the_post_thumbnail </code> will fail. Using your code you would get just th... | Query posts only with featured image | wordpress |
My project has two versions of the website - American and International. This is not localization, language is same, only content changes. I have created subdomain for the US version and kept international version on main domain. Now, I googled for solutions to redirect US users to US website by default and used Geo re... | I would say use a <code> $_SESSION['var'] </code> var or <code> $_COOKIE[] </code> to check if the link is clicked. Looks like the plugin is calling the <code> geo_redirect_client_location </code> function and then redirecting. <code> function geo_redirect_client_location(){ $geo = new Geo_Redirect(); $geo->checkIfR... | Redirect user on first visit based on geographical location | wordpress |
After every instance of <code> switch_to_blog() </code> you should call <code> restore_current_blog() </code> to restore the current (actually, previous) blog. But if you're looping through two or more blogs and calling <code> switch_to_blog() </code> on each, is there any reason not to use an additional <code> switch_... | After every instance of <code> switch_to_blog() </code> you need to call <code> restore_current_blog() </code> otherwise WP will think it is in a "switched" mode and can potentially return incorrect data. If you view the source code for both functions you will see those functions push/pop data into a global called <cod... | restore_current_blog() vs switch_to_blog() | wordpress |
For example, I write a new post with content "Today I'm happy, because I finally met the girl that @David told me about bla blah..." Once the post is published, there should be an email notification sent to David about this post that mentions him. Is there already such plugin? If not please help me with my implementati... | Twice edited according to kaiser's suggestions, unsecure version removed. <code> <?php function my_email_friend($post_id = '') { // get post object $post = get_post($post_id); // get post content $content = $post->post_content; // if @David exists if( 0 !== preg_match('/(@\w)/', $content, $matches) ) $friend_disp... | Writing a plugin that notify my friends of new post that mentions(@) them | wordpress |
I am working on the integration of an Amazon Webstore (Amazon Checkout) on a WordPress site using Amazon Documentation here . Has been a while since I worked with enqueueing external JScripts. I need to load two scripts from Amazon. I added some code to functions.php, but I seem to have made a mistake and I keep on get... | Try to save <code> jQuery.noConflict(); </code> as <code> jquery-no-conflict.js </code> . Then enqueue everything with proper dependencies: <code> <?php function img_scripts_with_jquery() { wp_enqueue_script( 'jquery-no-conflict', 'path/to/jquery-no-conflict.js', array( 'jquery' ), 'version', true ); wp_enqueue_scri... | Enqueue AWS Script | wordpress |
I'm currently working on a plugin that creates a custom post type. The issue I'm strugging with at the moment is that the custom post type is created fine, but when I go to add a new post I receive an "Invalid Post Type" error. The ui is hidden and I'm trying to link to it from add_submenu_page. I need assistance for h... | Magic here is: <code> 'show_ui' => true, 'show_in_menu' => 'plugins.php', </code> Try this: <code> function restaurant_menu_items() { $labels = array( 'name' => __('Restaurant Menu Items', 'post type general name'), 'singular_name' => __('Restaurant Menu Item', 'post type singular name'), 'add_new' => __... | Custom Post Type Link from Plugin | wordpress |
I'm working on a plugin and I've added a button to the tinymce editor that pops up a modal form, with options for the shortcode, and then inserts the shortcode with the selected options in to the post. The modal pops up a php file with an html form and some javascript in it. I'd like to use wp_dropdown_categories() ins... | So all I needed to do was add <code> <?php require_once("../../../../wp-load.php"); wp_dropdown_categories(); ?> </code> I had tried this before but it later occured to me that I was one directory off from where I should have been. I added an extra directory level (../) and the category dropdown shows up now. Thi... | Trouble using wordpress functions in a pop-up modal form | wordpress |
I am trying to add form field to a WordPress widget dynamically. So if the user want to add another date to an event they can click a button to get more fields. The question is: How do save newly created input fields to my database? Do i need to write a custom update function? Any tips? This is how the widget looks: Th... | Interesting Question! I've never seen repeatable fields used in Widgets. Giving a full Answer would require too much work/time, so I'll give you links to the resources I know, and hopefully you'll make this work and share the solution with us ;) All this examples deal with Meta Boxes, you'll need to copy the jQuery scr... | Adding Widget form fields dynamically | wordpress |
I have somee Item in the media library, where I want to retrieve the thunbnail from. I use the normal post thumbnail functions (tried some of them), with normal posts or cpts's the work fine. As media library items are handled, similiar to posts, I thought the normal wp thumb function could work there, too. There are a... | <code> wp_get_attachment_image($post->ID, 'size-1'); </code> The "post thumbnail" actually gets the featured image that is attached to the post. For an attachment, you want the attachment itself in a specific size, which isn't the same as the featured image. | Thumbnails for media Library images | wordpress |
I am using the latest WordPress version and when I use <code> <?php the_excerpt(); ?> </code> on the index page it doesn't show the post excerpt. I tried putting in the_content() instead and it worked, so I'm assuming there is something wrong. My code: <code> <?php get_header(); ?> <?php if (have_posts()... | I actually solved it myself, it turns out there was this piece of code which I removed that solved my problem: <code> function custom_excerpt_length( $length ) { return 0; } add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); </code> Not sure what it does though, but it doesn't seem like I need it. | Wordpress excerpt not working | wordpress |
I noticed that the default WP theme uses force_balance_tags for listing posts' excerpts. This way, it doesn't cause major html breakage whenever someone writes a post like <code> <div><b>This is an excerpt. <!--more--> and this is more text... </b></div> </code> It will close tags instead ... | <code> force_balance_tags() </code> is not a really safe function. It doesn’t use an HTML parser but a bunch of potentially expensive regular expressions. You should use it only if you control the length of the excerpt too. Otherwise you could run into memory issues or some obscure bugs . The other problem is: the func... | Why doesn't default Wordpress page view use force_balance_tags? | wordpress |
I making a widgetized footer with three widgetized areas (footer1, footer2, footer3), The problem is that even if there's no widgets assigned to any widgetized footer area, the footer is still there with his black background! what I want is to remove the footer if there isn't any widget assigned. | I would use the <code> is_active_sidebar() </code> conditional: <code> <?php if ( is_active_sidebar( 'footer' ) ) { ?> <div id="sidebar-footer"> <?php dynamic_sidebar( 'footer' ); ?> </div> <?php } ?> </code> That way, you can conditionally output the styled container itself. | How to test if the widgetized area has any widgets? | wordpress |
How can I make updates a public plugin of mine without breaking the plugin for all existing users. Firstly , I'd like to change the main plugin's class/namespace, because I'd like it to be similar to other classes in the plugin that it extends. So I'd like to change <code> class some_class(){} </code> to <code> class S... | Class names are case insensitive in PHP (with one exception ), so that should not be a problem. Accessing your main plugin instance for a class is possible with a static method <code> get_instance() </code> ( example ). You don’t have to build a Singleton for that. And it should not break backwards-compatibility. If yo... | Update a Plugin while maintaining back compatibility: general | wordpress |
Does anybody know of a way to modify the wordpress template process so that a single custom post type can be displayed on two separate templates based on the value of a custom field. For example I have a single Custom Post Type called "plans" It is using the single-plans.php and archive-plans.php files as templates by ... | Might be side-stepping your question, but can you use get_template_part ? <code> <?php get_template_part( 'plans', get_post_meta($post->ID, 'my_custom_field', true ) ); ?> </code> Then create "plans_plana.php" and "plans_planb.php" (assuming that 'my_custom_field' can have values of 'plana' and 'planb'). twent... | Multiple templates for single custom post type | wordpress |
How can I change the size of a featured image thumbnail on the Edit Post screen for one of my custom post types? Please note that I am looking to modify the size of the image displayed in the admin 'Edit Post' screen, and not on the front end of my site. The size is determined by WP itself at the moment, and I don't se... | From my past research I concluded that there is no sane way to affect the featured images box with actions and filters. My solution was to use jQuery inserted on the admin_head hook, to change things after they are loaded. What I wanted was to add some textual detail outlining how the featured image would be used by th... | Change size of featured image in Edit Post screen | wordpress |
I am trying to create a shortcode that will return a link to a book on Amazon with a specific affiliate tracking code specific to the author. I created a user option called "amz" to hold the author's tracking code. This works fine when I'm using it elsewhere. This is the shortcode I created: <code> function amazon_link... | <code> the_author_meta() </code> prints the content immediately. Use instead: <code> $amztrack = get_the_author_meta( 'amz', FALSE ); </code> This will return the value. | How to use author meta in shortcode? | wordpress |
I want to learn how to run commands through WP rather than SQL commands I have a SQL command: <code> SELECT post_id, (select meta_value from wp_postmeta where meta_key = a 'geo_latitude' AND x.post_id = a.post_id) as lat is NOT NULL, (select meta_value from wp_postmeta where meta_key = b 'geo_longitude' AND x.post_id =... | Arbitrary SQL query can be run via <code> wpdb </code> by using <code> get_results() </code> method: <code> $results = $wpdb->get_results( $query ); </code> You can work through documentation for <code> wpdb </code> at Codex to gain basic understanding of how it works. | learn to run wpdb class | wordpress |
In the theme I'm using there is a custom.php file where the following code issues a pre_get_post function which adds the custom post types to the original query object. I've learned that you cannot conditionally load this... and it is breaking BBPress pages on forums.php by refusing BBP to fully load certain post types... | I'm not 100% clear on what the problem is, but I would start with putting the conditions inside the function instead of wrapping the entire function. <code> add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { if (!is_admin()){ global $oswcPostTypes; if(empty( get_query_var('suppress_filte... | pre_get_posts and BBPress in Swagger Theme | wordpress |
I am trying to add another field (subtitle) to my already created and existing custom post_type: team (code from functions.php in my * child *theme) <code> <?php /** * Custom Post type register framework */ include(get_stylesheet_directory(). '/inc/acpt/init.php'); add_action('init', 'makethem'); function makethem()... | In your code, you are using: <code> add_filter( 'team_Meta_Box', 'team_sample_metaboxes' ); </code> On the site you linked to, they are using: <code> add_filter( 'cmb_meta_boxes', 'wpb_sample_metaboxes' ); </code> So my question is: did you change all instances of "cmb" to "team" in the init.php file? If you did, then ... | Add additional field to custom post_type | wordpress |
I using the built-in gallery in wordpress to store and sort images inside a custom post type. In the theme I was using: <code> $attachments = get_posts( array('post_type' => 'attachment', 'post_parent' => $post->ID, 'orderby' => 'menu_order' ) ); </code> The above code returns the gallery images correctly, ... | You are correct. The menu_order is no longer used for media in the gallery. Not sure if this is by design or an oversight. Could be by design since you can now include media in a gallery even if it is not "attached" to the page/post. In any case, below is the method I use to grab the ids and get the attachments based o... | Ordering of gallery images without using shortcode in theme | wordpress |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.