Maybe this has been asked somewhere, but let me try to explain:
In a plugin of my wordpress website, I have a function that I want to overwite, but it won't let me.
Here is how it looks like:
function this_is_funtionA() {
$content = this_is_functionB('somevalue1', 'somevalue2'); // this function I am trying to overwrite
return $content;
}
add_filter('the_content', 'this_is_funtionA', 5);
function this_is_funcionB($item1, $item2) {
// some code
}
How can I overwrite this_is_functionB?
Related
In my theme function.php i am trying to add shortcodes for myHeader, myFooter etc .
Inside myHeader(), myFooter() function i added another function like fn_1(), fn_2(), fn3_() etc these function would be change weekly or monthly basis.
Is it possible to call a shortcode as written below
function myHeader(){
fn_1();
//fn_2();
}
function myFooter(){
fn_2();
// fn_3();
}
add_shortcode('myFooter', 'myHeader');
add_shortcode('myFooter', 'myFooter');
function fn_1(){
return 'something for 1';
}
function fn_2(){
return 'something for 2';
}
function fn_3(){
return 'something for 3';
}
In my post i call my shortcode as [myHeader] and [myFooter]
It is possible, you just need to return something inside your shortcode methods. Shortcode functions also require some variables, though they don't actually have to be used.
eg.
function myHeader($atts, $content = null){
$temp = fn_1();
return $temp;
}
$atts is required to create shortcode if you are passing $atts or not.
You can hook functions into the site footer using the following:
function to_footer() {
$content = 'I am in the footer';
echo $content;
}
add_action('wp_footer', 'to_footer');
But is there a similar approach to add a function inside the post's footer (not site footer) in single page views?
The closest you can get (without changing template files) is this
function to_footer($content)
{
return $content . 'I am in the footer';
}
add_action('the_content', 'to_footer');
This will add your thing after post content
If you do not mind editing your templates, try the following
function alt_footer()
{
do_action('alt_footer');
}
in functions.php of your theme. Then call alt_footer() in your template where you need it, then
function to_footer()
{
echo 'I am in the footer';
}
add_action('alt_footer', 'to_footer');
I'm seeing a lot of guides on how to add more classes to a Wordpress body tag, but is there a way to remove all classes from a specific page template, more specifically the search page?
Here's where I'm at so far.. not much sorry.
add_filter('body_class', 'remove_search_class');
function remove_search_class($classes){
global $post;
if(is_search()) {
// find ".search & .search-results"
}
return // no classes within <body>
}
add_filter('body_class','alter_search_classes');
function alter_search_classes($classes) {
if(is_search()){
return array();
} else {
return $classes;
}
}
try adding this in your functions.php
I'm having problem in using wp_rewrite.. can't seem to make it work..
I need to change this URL:
/eduedu/wp-content/plugins/workwork/admin/templates/tcpdf/samp/flash.php
to
/eduedu/generator
function create_rewrite_rules() {
add_rewrite_rule($wordpress_root.'/generator/?$', 'wp-content/plugins/workwork/admin/templates/tcpdf/samp/flash.php');
}
function flush_the_rewrite_rules () {
flush_rewrite_rules;
}
add_action('init', 'flush_the_rewrite_rules');
add_filter('generate_rewrite_rules', 'create_rewrite_rules');
try:
function flush_the_rewrite_rules () {
flush_rewrite_rules();
}
also, are you sure $wordpress_root is being initialized, you might want to debug its value to see if it is what you are expecting.
add this code to your functions.php file
function site_router() {
global $url_array;
$url_array = explode("/",$_SERVER['REQUEST_URI']);
$route = $url_array[2];
$template_dir = 'wp-content/plugins/workwork/admin/templates/tcpdf';
switch($route) {
case 'generator':
load_template($template_dir.'/samp/flash.php');
die();
break;
}
}
add_action( 'send_headers', 'site_router');
Itll find the url domain.com/edenudu/generator and load in the template from the file you want.
No need for messing about in htaccess and no need for creating rewrite rules which are mostly used for creating pretty permalinks for existing post/pages
I developed a plugin with Settings link that was working fine in WordPress 2.7. Version 2.8 brings some additional security features that cause Settings link displaying message: You do not have sufficient permissions to access this page.
This is the API hook I use to create link:
function folksr_plugin_action($links, $file) {
if (strstr($file, 'folksr/folksr.php')) {
$fl = "Settings";
return array_merge(array($fl), $links);
}
return $links;
}
add_filter('plugin_action_links', 'folksr_plugin_action', 10, 2);
Full source code available at plugin page.
Settings screen does not contain any additional logic, just a couple of options and HTML echoed to the screen.
Suprisingly enough, Codex does not return anything for search phrase "plugin_action_links". Can you provide example or point me to working code for Settings link in Plugins menu?
I found the solution to my own problem by analyzing sources of some random plugins. I must say - what an unpleasurable experience that was! But hey, here's the solution.
It turns out that in order to build Settings link, it needs to be registered first. The following code is a stub that does the trick:
class MyPlugin {
public function __construct() {
add_filter('plugin_action_links', array($this, 'renderPluginMenu'), 10, 2);
add_action('admin_menu', array($this, 'setupConfigScreen'));
}
public function renderPluginMenu() {
$thisFile = basename(__FILE__);
if (basename($file) == $thisFile) {
$l = 'Settings';
array_unshift($links, $l);
}
return $links;
}
public function setupConfigScreen() {
if (function_exists('add_options_page')) {
add_options_page('MyPlugin settings', 'MyPlugin', 8, basename(__FILE__), array($this, 'renderConfigScreen'));
}
}
public function renderConfigScreen() {
include dirname(__FILE__) . '/MyPluginSettings.php';
}
}
I have working admin menu links on my plugins working in 2.8+. My function looks like this:
function plugin_action_links( $links, $file ) {
if ( $file == plugin_basename(__FILE__) )
$links[] = 'Settings';
return $links;
}
My add_filter line is mostly identical. I think the first thing to try is adding the use of the admin_url function.
Hope that helps.