I want to change the wordpress blog widget title such as Archives, Recent Post, Recent Comments.
I search in many ways. I know it is execute in the file of default-widgets.php. The lines is
$title = apply_filters('widget_title',
empty($instance['title']) ? __('Recent
Posts') : $instance['title'],
$instance, $this->id_base);
I made the changes in that but it is not reflect anything. So please help me.
Where and How should be changes this ?
I really don't think hacking around in default-widgets.php is a good idea, unless you really know what you are doing. Changing default-widgets.php means that you have to account for upgrading Wordpress.
Instead, I would suggest creating a new widget to do what you would like it to do and not play around with the Wordpress core.
Here's a decent tutorial on creating this: http://www.lonewolfdesigns.co.uk/create-wordpress-widgets/
I just found this post, and it's exactly what I needed -- I think it might work for you too. It shows you how to create a filter for the widget_title callback to modify the title however you want to.
http://coderseye.com/2010/modifying-widget-titles-in-wordpress.html
I have same problem too, after reading you tips i have find it out, just edit the 'change here' , problem would be solved.
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'change here' );
You can change the title using a filter hook widget_title
function new_widget_title($title) {
if ($title == 'Recent Posts') $title = "Greatest posts";
return $title;
}
add_filter ( 'widget_title' , 'new_widget_title', 10, 3);
for WordPress 2.8
Just open the file named:default-widgets.php which can be located inside the wp-includes directory and delete/modify there and upload to ur server, as simple as that. *This was found before in the widgets.php in previous versions.*Also to remove the search for title and replace it u can just delete the text in the php file.This is the line for changing title -
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title']);
}
Keep in mind though that if and when you upgrade to the next version of WP you will also update the /wp-includes directory thus overwriting the defaults-widgets.php file, so make a backup copy.
Also look here to Disable default WordPress widgets like archives,meta-links,recent-posts etc..
For adding widgets like archives, recent posts:
On dashboard, go to Appearances->Widgets.
On left hand side of that window, you will see archives, just move the cursor on it, uou will see a hand symbol on it. Then just drag and place it on right side of that window, below
the main sidebar. Then, give the title as you want and click save and so on, the same for recent posts.
Then, on left top of the blog or website, click your website or blog name to see your archives, recent posts as sidebar.
Related
EDIT: Found my old code, that worked, and got it fixed that way. Also gonna use a plugin to add custom functions, to avoid it dissaperaing again with next theme update (Thanks Heba). And the code:
function foo_modify_query_order( $query ) {
if (get_the_ID()==80) { $query->set( 'orderby', 'title' ); $query->set( 'order', 'ASC' ); } } add_action( 'pre_get_posts', 'foo_modify_query_order' );
So, it should be a simple task, but I have no idea why it's not working by now. I have tried everything, every Google link is purple, so now I hope someone can tell me what it is, I'm doing wrong.
I should start by mentioning that it's a Divi theme, but I did get it to work a few months ago, but forgot how, and I can't recreate it now.
I'm just trying to sort the main query alphabetically (A-Z), but only on a page called recipes. The site have all the recipes as posts, together with their blog posts, but the blog posts are sorted by date and showed on a separate page, which works fine.
But weird stuff are happening, when I try and alter it. If I use this code, it actually works, but the blog page also get sorted alphabetically, which it shouldn't.
function foo_modify_query_order( $query ) {
if (is_archive()) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'foo_modify_query_order' );
Which doesn't make sense to me, since it's posts? Out of all the ways I've tried, it only sorts if I use is_archive().
If I try to make it check for a specific page first, like && is_page('recipes') I get an error.
If I just add if (is_page('recipes')){ echo 'Recipes'; } it works, but if I try to add the sorting inside, I get nothing.
So partially working, but I can't combine the two. Is it a Divi issue or am I doing it wrong? Hope anyone can help, I've tried so many different things now. Cheers :)
I would recommend creating a child theme where you will create a new page template to be used in the 'recipes' page.
First, use Child Theme Configurator plugin to set a new child theme, don't forget to select Copy Menus, Widgets and other Customizer Settings from the Parent Theme to the Child Theme option to keep your settings:
After that, from files tab in the child theme configurator, copy the page template used for blog (or the page template used in 'recipes' page).
After that, change the file name, and the name written in the top of the page template file after Template Name, to recipes ordered alphabetically or any name you would prefer like next:
/*
* Template Name: recipes ordered alphabetically
*/
You can add these args to the query:
$args['orderby'] = 'title';
$args['order'] = 'ASC';
And change 'recipes' page template to the new created one.
For more detailed answer, Please insert the code used in the page template.
Pretty much every guide ive come across for adding php pages to Wordpress involves adding it at the theme level. e.g. How to add a PHP page to WordPress?. I want to add a new public facing page to multiple sites via a plugin. I dont want to have to add this to dozens of themes. If i can add it ad the plugin level it will work for all sites.
I have this working, but i need some way of injecting this into a theme. In order to get the sidebar and stuff without having to add custom css for each theme.
Ive started by adding a rewrite rule
RewriteRule ^mypage /wp-content/plugins/myplugin/mypage.php [QSA,L]
Then page.php contains
require_once('../../../wp-blog-header.php');
get_header();
//custom php content
//get_sidebar(); // how to get this working.
get_footer();
This also works, but the problem im having is with sidebars. Some themes dont have them and others do. Not all sidebars are 30% etc. I dont know how to build the div structure here to make it work. Some themes are 100% page width, but this looks ugly when viewed on other themes that are a fixed width. I have been able to come up with some compromises, but id rather be able to do this right.
In summery my main question here is. Is it possible to call a method that will inject html into a theme page. e.g. generate_page($html);. This method will then go to page.php of the theme and inject $html into the content area of the theme.
Edit
In an attempt to dynamically inject content into an unknown theme ive done the following
global $post;
$post->post_content = "TEST PAGE content";
$post->post_title = "Page Title";
$post->post_name = "test-page";
include get_template_directory()."/page.php";
This works for some themes and not others. Some themes will display this post just fine, but others (the default wordpres twenty fifteen theme) are displaying this post and then every other post in the database after it. Im not sure where or why its pulling all of these posts, but if i can get it to stop it looks like this will be a valid solution.
Then u could try to load a specific template page in specific case.
function load_my_template( $template )
{
if( is_page() )
$template = plugin_dir_path(__FILE__) . "dir_to/my_template.php";
return $template;
}
Or change the content that is use on loading page
function load_my_content( $content )
{
global $post;
$id = $post->ID;
if( is_page() )
{
ob_start();
include plugin_dir_path(__FILE__) . "dir_to/my_template.php";
$content = ob_get_clean();
}
return $content;
}
In your __construct()
add_filter('template_include', array($this,'load_my_template') );
add_filter("the_content", array($this,"load_my_content" ) );
add_filter("get_the_content", array($this,"load_my_content" ) );
Hope that help u.
Tell me if it's not corresponding with your question.
I'm having an irritating problem with my Wordpress site I was hoping you might be able to help me with.
Basically, I have a page - Case Studies, which was called 'case-studies' in the nav structure. It was later removed and re-added, forcing it to 'case-studies-2'. Is there any way of editing this? I tried changing the permalink within the page itself but it reverts to 'case-studies-2' after being changed.
My second issue is with the custom post type 'Case Study' which ties into this page. I can get the page to pull the custom posts in a list, but their permalink goes to a 404 and resetting the permalink structure didn't fix it!
Lastly, my attempts to resolve this problem have led to my Case Studies page bouncing back to the homepage no matter what I do with the template file.
Thanks in advance folks,
Graham
The first page of Case Study with nav-structure case-studies is still available in trash of post so firstly delete that page from trash & then edit your new case study page and in that edit permalink and remove 2 just like case-studies-2 to case-studies
For second issue you have to register your custom post type to theme's function.php file
For this add this code to function.php file
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'page', 'album', 'movies','music_review') );
return $query;
}
after this reset your permalink
Issue resolved - the old file was in the bin, not properly removed. Deleting it from there allowed me to update the permalink directly on the page :)
Thanks for your help, peeps!
Does anyone know of a way to change the title of a page that is created dynamically in Wordpress? The pages in question are created dynamically via a plugin, and do not appear in the list of pages or Wordpress SEO in the admin section.
Here is an example of a page I would like to change the title of: http://www.forestlakechevrolet.com/inventory/New/
The inventory tool is maintaining the inventory of two dealerships, but only one is featured on this site. So it uses an SEO title based on the makes available at both dealerships.
Essentially, I am wondering if there is a function that I could add that would say "If URL is ... then force page title to be ***."
Does anyone know how to do this?
Thank you,
Jared Wilcox
Just use the wp_title filter
Add something like this to your theme's functions.php file:
<?php
function assignPageTitle( $title ){
global $post;
if ($post->post_name === "test") {
$title = "Title goes here";
}
return $title;
}
add_filter('wp_title', 'assignPageTitle');
?>
You may also need to change your theme's header file if the wp_title call is adding the Site Name.
BTW, WordPress questions are better asked on https://wordpress.stackexchange.com/
Lots of people, both here on SOW and elsewhere, are having my same exact problem.
I've installed the BBpress plugin on my site here. This plugin enables a FORUM on the site.
I've wrestled for days (to no avail) on this documented issue where the plugin causes the wrong menu item to be highlighted when any Forum sub-menu item is chosen. Instead, the Blog menu item gets highlighted by default.
Check it out: Click on Forum and this resulting page highlights the "Forum" menu item okay. But click on "Test forum" (or drill down into any other Forum item) and the resulting page always has "Blog" highlighted.
Here's what I know so far:
It can't be fixed with CSS alone.
I am using Permalinks (with "Post name" selected)
PHP assigns a .current-menu-item and/or a .current_page_item class (along with their corresponding -ancestor and -parent classes) to menu items based on the page you've navigated to. For some reason, it is failing to see any Forum submenu as a current page. As a result, it is defaulting to "Blog" as the current page item.
So I know I need to do the following:
have Wordpress check the URL upon each page load
if "/forums/" is part of the URL, remove all .current-menu* and .current_page* classes (the wildcard is necessary to purge the ancestor/parent classes).
then assign .current-menu-item and .current_page_item classes to the "Forum" menu item.
The problem is, while I think i'm getting close, I don't know how - exactly - to do this.
I've tried a bunch of things.
I found this Jquery solution but don't know how to implement it, nor am I confident in this approach:
// First add a “forum-class” to your forums menu item in your custom menu
// Then add this to your js file with YOURURL = the url of your site and forums = your forums slug :
$(function() {
var forumURL = window.location.href.indexOf("YOURURL/forums/");
if(forumURL > -1){
$('li.forum-class').addClass('current-menu-item');
}
});
Then, I found this approach which seemed closer to what I wanted, but it introduces a new class and doesn't seem to clear the incorrect classes from the Blog menu. Plus, I don't know where exactly to put this code, or where to create the js file.
if (strtolower($thats_all->post_title) == "forum" || strtolower($thats_all->post_title) == "forums") {
$addclass = ' class="current_page"';
} else {
$addclass = '';
}
Finally, I found this which is what I think I need, but I'm having trouble implementing it (I've tried sticking it in my menu-primary.php and header.php but no go).
// this forces the class current-menu-item to a menu item which I named 'forums'
add_filter('nav_menu_css_class', 'remove_link_parent_menu_classes', 420 ,3);
function remove_link_parent_menu_classes($classes, $item, $args){
if(strpos($item->url, '/forums/') !== true)
return array_diff($classes, array('current_page_item', 'current-menu-item'));
return $classes;
}
I think I'm close. Really close. Just need a push in the right direction. I need to know:
will the latter solution above work?
which file, and where exactly in the file, do I need to place the code?
Thanks!
I finally cracked it! Using the above clues, I figured out this code that worked for me.
add_filter( 'nav_menu_css_class', 'namespace_menu_classes', 10, 2 );
function namespace_menu_classes( $classes , $item ){
if ( get_post_type() == 'forum' ) {
$classes = str_replace( 'current_page_parent', '', $classes );
$classes = str_replace( 'menu-item-16', 'current_page_parent', $classes );
}
return $classes;
}
Copy the above at the end of the function.php file.
Then change 'forum' to the slug name you've chosen and replace 'menu-item-16' with the correctly numbered menu item that you want highlighted (you will need to use your web browser's developer tools to inspect your site to be able to find this).
This took me a week to figure out (and learn the php required)! Good luck and hope this helps everyone else out there.