wordpress-theming

Best Practice for Including JS (with PHP) in WordPress Functions file

ぃ、小莉子 提交于 2019-12-05 01:35:50
问题 I'm building a custom WordPress theme and have a quick question regarding WordPress and the Functions.php I've got 500 lines of jQuery that run for a portion of my custom theme admin panel. The jQuery code is located inside of my functions.php file, called when the custom admin menu page is displayed. Ideally, I would like to move the JavaScript out of the functions.php file and use wp_register_script + wp_enqueue_script, but I also have some php code mixed in with the script. See below: /

Adding two sidebars in wordpress child theme

折月煮酒 提交于 2019-12-04 21:36:01
In Wordpress I want to make two sidebars. One will be in left hand side of the content and the other one will be in the right hand side (default sidebar) in twentyelven theme. For that I made little bit customization to my twentyeleven child theme. In functions.php I made this changes register_sidebar( array( 'name' => __( 'Left Hand Sidebar', 'buygames' ), 'id' => 'sidebar-left', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => "</aside>", 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); Then in sidebar-page.php I added this code <div

Wordpress use functions.php to run function only on specific page template

允我心安 提交于 2019-12-04 20:55:12
I have a following code to check if current used file is tmp_home_page.php , but when I do echo $template_file; it is showing functions.php add_action('template_redirect', 'are_we_home_yet', 10); function are_we_home_yet(){ global $template; $template_file = basename((__FILE__).$template); if ( is_home() && $template_file == 'tmp_home_page.php' ) { // do stuff } } Any idea how to make sure that my do stuff is only run on home page and when given template is in use? You're looking way too hard into this, there's a wordpress function for that. is_page_template() if( is_page_template( 'tmp_home

WordPress wpautop issue

百般思念 提交于 2019-12-04 19:22:53
I have disabled wpautop through the given code: remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); This function works. But my actual problem is that, it removes custom "p" tags that I have manually used in the content. So the problem is that when I don't use the above given code, there are automatic p tags that destroy my website and when I disable them, custom p tags are also disabled. The easiest and simplest way to avoid wpauto issue is to understand how wpautop works, Any plain text, or inline element that aren't wrap with block element will be

Wordpress Docker won't increase upload limit

醉酒当歌 提交于 2019-12-04 17:24:40
问题 I am trying to increate the upload limit of my Dockerized Wordpress instance to 150M. [filename] exceeds the maximum upload size for this site. I have created an uploads.ini file and attached it by volume to the instance. Yet I still can't get the Wordpress media uploader to increase it's limit. Docker-compose.yml: version: '2' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: password1 MYSQL_DATABASE: wordpress MYSQL_USER:

remove published post notice while error handled

江枫思渺然 提交于 2019-12-04 17:10:35
im creating an error handler for a custom post type. add_filter( 'wp_insert_post_data' , 'filter_post_data' , '99', 2 ); function filter_post_data( $data , $postarr ) { //error handling if($data['post_type'] == 'post_annunci') { if($postarr['annuncio_prezzo'] == '' || !is_numeric($postarr['annuncio_prezzo'])) { $errors .= 'Annuncio non salvato, devi inserire un prezzo con valori numerici.</br>prezzo = '.$postarr['annuncio_prezzo']; update_option('my_admin_errors', $errors); $data['post_status'] = 'draft'; } } return $data; } add_action( 'admin_notices', 'admin_error_handler_annunci' );

Random permalink key in wordpress

末鹿安然 提交于 2019-12-04 17:05:03
I want to have a custom permalink for each new post in WordPress like: http://mysite.com/x5Kvy6 (like bit.ly). I tried this little script, but it adds only 5-digit numbers to the post title in the permalink. function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { if($slug!=""){ $random=rand(11111,99999); //I needed 5 digit random $slug .= "-" . $random; } return $slug; } How can I make a random key instead of the post title? I have not researched URL shorteners or redirection methods. Any idea is welcome! function wp_unique_post_slug($col,$table='wp_posts'){

My settings are not saving in wordpress theme options page

▼魔方 西西 提交于 2019-12-04 17:04:43
I am trying to create a theme options page based on WordPress's Settings API. When I go to check the options.php page in my browser (ex. http://mysite.com/wordpress/wp-admin/options.php ), I see an entry for coolorange_options but it is empty. This happened after I added a url, width and height to the text fields. So far, I have enough code written to get the information and store it to the database, but not to retrieve it for anything. I referenced a tutorial in the php comment at the top of the code. Considering that I don't know much php or programming, something must be wrong here, I just

Wordpress - Nested list of categories & subcategories

心不动则不痛 提交于 2019-12-04 16:59:00
Im trying to display a list of my wordpress categories with nested subcategories. So far i've only been able to get a list of parent categories or a list of subcategories excluding parents but I haven't been able to join the two together. This is the sort of result I am looking to create: Parent Category Subcategory Subcategory Parent Category Subcategory Parent Category Subcategory Subcategory Subcategory EDIT: The idea for this is to create a custom category page. The HTML is as follows: <h1>Categories</h1> <ul class="blocks"> <li> <img src="http://placehold.it/250x250" alt="title" /> <h2

Wordpress Authenticate Filter

╄→гoц情女王★ 提交于 2019-12-04 14:58:33
I'm currently trying to override Wordpress' wp_authenticate function (without modifying the core files, mainly pluggable.php), however I'm not sure if I'm going about it the correct way. There are two great references (see below), but they don't explicitly state what to do in order to prevent the login provided certain criteria are met. In short, I'm trying to prevent registered users who have not activated their account. I've already implemented creating a user with a md5 unique id in the usermeta table (attached to their user id). I'm basically trying to check for that "activation_key' value