Create onClick Event to Re-load a Widget

I think you something like this. HTML Add this in widget <a href=”https://wordpress.stackexchange.com/questions/254474/javascript:void(0)” id=”add_my_fav”>Add To Favourite<span id=”favCount”></span></a> Ajax Add this in template <?php $nonce = wp_create_nonce(‘addToFav’); ?> <script> jQuery(document).read(function(){ jQuery.ajax({ url: ‘http://example.com/wp-admin/admin-ajax.php’, data: {action:”add_to_favourite”, secret:”<?php echo $nonce; ?>”}, method: ‘POST’, success: function(res){ jQuery(‘#favCount’).html(res); } }) }) </script> PHP Add this in functions.php function addToFavourite(){ if(isset($_POST[‘secret’]) … Read more

Simple ajax call not working in wordpress plugin

You have to put the name of your wp ajax action in your data when you do the ajax call. I assume the ajax url is correct. jQuery( document ).ready(function(){ //alert(“Jquery Loaded”); jQuery(“#pub_search”).click(function(){ alert(“You clicked”); event.preventDefault(); var term= $(“#sterm”).val(); console.log(‘your term send: ‘+term); var data = {‘nwterm’: term, ‘action’: ‘litsearch’} $.get(litsearch.ajaxurl, data, function(data){ $(“#container”).html(data.response); }); … Read more

Plugin CSS not enqueing

If you want to add inline CSS, use wp_add_inline_style(). <?php /** * Plugin Name: WPSE 257470 * Description: WordPress StackExchange question 257470 * Plugin URI: https://wordpress.stackexchange.com/questions/257470/ * Author: Nathan Johnson * Licence: GPL2+ * Licence URI: https://www.gnu.org/licenses/gpl-2.0.en.html */ //* Don’t access this file directly defined( ‘ABSPATH’ ) or die(); if( ! class_exists( ‘wpse_257470’ ) ): … Read more

Custom posts don’t work

After custom post type registration, that is register_post_type() , try adding function flash_rewrite_rules(); This will automatically flush all rewrite rules so you won’t need to go to permalink settings each time. See this page: https://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation Example: add_action( ‘init’, ‘my_cpt_init’ ); function my_cpt_init() { register_post_type( … ); flush_rewrite_rules(); } As it’s said in the docs, it’s … Read more

custom post type not showing in menu

// portfolio code function codenovo_portfolio_init(){ $labels = array( ‘name’ => _x(‘Portfolio’, ‘post type general name’), ‘singular_name’ => _x(‘Portfolio’, ‘post type singular name’), ‘add_new’ => _x(‘Add New’, ‘portfolio’), ‘add_new_item’ => __(‘Add New Portfolio’), ‘edit_item’ => __(‘Edit Portfolio’), ‘new_item’ => __(‘New Portfolio’), ‘view_item’ => __(‘View Portfolio’), ‘search_items’ => __(‘Search Portfolio’), ‘not_found’ => __(‘No portfolio found’), ‘not_found_in_trash’ => … Read more

WordPress theme custom capabilities not works

add_action( ‘init’, ‘register_cpt_gallery’ ); function register_cpt_gallery() { $labels = array( ‘name’ => _x( ‘Galleries’, ‘gallery’ ), ‘singular_name’ => _x( ‘Gallery’, ‘gallery’ ), ‘add_new’ => _x( ‘Add New’, ‘gallery’ ), ‘add_new_item’ => _x( ‘Add New Gallery’, ‘gallery’ ), ‘edit_item’ => _x( ‘Edit Gallery’, ‘gallery’ ), ‘new_item’ => _x( ‘New Gallery’, ‘gallery’ ), ‘view_item’ => _x( ‘View … Read more

Tried in different ways but sidebar not working?

add_action( ‘widgets_init’, ‘Y_widget_register’ ); You have a typo – use underscores. Here is the working piece: function Y_widget_register() { register_sidebar(array( ‘name’ => esc_html__(‘Sidebar’, ‘Y-07’), ‘id’ => ‘y-sidebar’, ‘description’ => ‘Dynamic Right Sidebar’, ‘before_widget’ => ‘<section id=”%1$s” class=”y-widget %2$s”>’, ‘after_widget’ => ‘</section>’, ‘before_title’ => ‘<h2 class=”y-widget-title”>’, ‘after_title’ => ‘</h2>’ )); } add_action(‘widgets_init’, ‘Y_widget_register’);

Adding settings link to plugin doesn’t work

The code is working and tested. Activate your plugin you will see the settings link add_filter( ‘plugin_action_links_’ . plugin_basename(__FILE__), ‘apd_settings_link’ ); function apd_settings_link( array $links ) { $url = get_admin_url() . “options-general.php?page=my-plugin”; $settings_link = ‘<a href=”‘ . $url . ‘”>’ . __(‘Settings’, ‘textdomain’) . ‘</a>’; $links[] = $settings_link; return $links; }

Will setcookie work if there is a cache plugin installed?

It will most likely depend on the plugin, but you should also remember that your content might be cached also in caching proxies as well. https://stackoverflow.com/questions/9334393/proxy-cacheing-what-about-cookies In other words, if your output is different to two different users, than you can not use caching. The way to go around this is to make the decision … Read more