Hot answers tagged

25 votes
Accepted

Get parent page url to show up when it is in child pages

You can use something like this to get the parent page URL (and show its page title): <?php if ( $post->post_parent ) { ?> <a href="<?php echo get_permalink( $post->post_parent ); ?...
user avatar
21 votes

Add CSS Class to Link in TinyMCE editor

One option is to add a class to the Styleselect menu in MCE. Adapted from the "TinyMCE Custom Styles" Codex page you first need to add the style select to the editor: // Callback function to insert '...
user avatar
  • 9,947
20 votes
Accepted

Add custom options to the wplink dialog

The dialog HTML comes from WP_Editors::wp_link_dialog() but no hooks in there. We could instead use jQuery to append the custom HTML to the link dialog and try to override e.g. the wpLink.getAttrs(), ...
user avatar
  • 64.1k
13 votes
Accepted

Redirecting to old domain after migration

My issue is resolved, I am posting this as an answer so that someone else can benefit out of it. My issue was, siteurl and homeurl were not updated, so I have placed define('RELOCATE',true); in my wp-...
user avatar
  • 453
10 votes

Redirecting to old domain after migration

I had the same problem (works fine now), here is what i done instead of try to access to the admin panel whit yoursite.com/wp-admin i tried with yoursite.com/wp-login.php and it took me to the admin ...
user avatar
  • 109
9 votes
Accepted

How to get a page url by a page id?

You're probably getting that error because WordPress doesn't have the $wp_rewrite global loaded yet for some reason. Either something deactivated it, or you're trying to run those functions before ...
user avatar
  • 1,607
9 votes
Accepted

How to use wpLink without editor?

There is not ethical way of doing this. But still there is a way to do this. WordPress wrote wpLink script keeping in mind that editor is there but still WordPress handle when editor is not there (...
user avatar
  • 4,684
8 votes

Redirecting to old domain after migration

Run the following when you are changing domain: UPDATE wp_options SET option_value = 'https://yournew.domain' WHERE option_name = 'siteurl'; UPDATE wp_options SET option_value = 'https://yournew....
user avatar
  • 781
8 votes
Accepted

Removing link '<a>' from '<li>' menu for some "links" without JS

Assuming you're using wp_nav_menu() to display your navigation you could apply a walker that looks for css classes: $items_wrap = '<nav class="...">'; $items_wrap .= '<ul id="%1$s" class="%...
user avatar
  • 19.6k
8 votes

Using filters to change href of nav menu page link

You are on right track, with few minor kinks. You need to modify $atts and return it. Any arguments after the first one are provided for information and should not be changed. You need to tell ...
user avatar
  • 97.7k
7 votes
Accepted

Add custom menu item using wp_nav_menu_items filter

I've created these two functions you may use to add custom items to a given menu item present in your menu (page, post, link...). In your case, you can add these function to your functions.php and ...
user avatar
  • 585
7 votes

How to get current page menu item name instead of full menu item list

Within each menu item, object_id holds the ID of whatever object the menu item refers to. This will be a post / page / CPT / term ID. If it's a custom link, the ID refers to itself. (If you want to ...
user avatar
  • 76.2k
7 votes
Accepted

How to print translation supported text with HTML URL

Since esc_html_e will escape HTML link (hence will show the HTML anchor as plain text), you'll need to segment the text and escape the non-HTML part with esc_html_e or esc_html__, and print the HTML ...
user avatar
  • 7,184
6 votes
Accepted

How can I store page ID in a post instead of other selected permalink?

Add that to your functions.php: function wp_link_query_mod ( $results ){ if( count( $results ) ){ for( $i=0; $i<count($results); $i++ ){ $results[$i]['permalink'] = ...
user avatar
  • 168
6 votes

Modify links when inserted by WYSIWYG editor

The HTML for the inserted internal links are generated by Javascript, so I'm not aware of any easy way to change it. The HTML generation is controlled from the wpLink.htmlUpdate method (HTML mode) ...
user avatar
  • 64.1k
6 votes

Insert Media - Attachment - Link to : Remove the "attachment page" option

These options are hardcoded into the tmpl-attachment-display-settings Underscore media template in the /wp-includes/media-template file: <script type="text/html" id="tmpl-attachment-display-...
user avatar
  • 64.1k
5 votes

Links redirecting to localhost after migration to server

if anyone comes across with this issue, I resolved it by editing both the 'home' and 'siteURL' fields in the wp-options table of the database on the server (not the localhost one) to replace the '...
user avatar
5 votes

Linking to page with all posts

I know this question was answered years ago, but for those looking for a solution that find this page, there is a MUCH easier solution. Go to Posts > Categories and click on Quickedit for the default ...
user avatar
5 votes

Adding different classes to anchor in navigation menu

you can follow the below Steps : Step 1 : In the wp-admin, go to Appearance -> Menus,put the class on the menu item here "CSS Classes (optional)". If you can't see the "CSS Classes (optional)" in the ...
user avatar
5 votes

List all taxonomy terms / Show links if posts are attached, else names

I didn't understood your question well, but try this. Explanation is in the comments. // your taxonomy name $tax = 'post_tag'; // get the terms of taxonomy $terms = get_terms( $tax, [ 'hide_empty' ...
user avatar
  • 1,312
5 votes

Redirecting to old domain after migration

Changing wp_options field will help a little, but sometimes your pages, posts and plugins will use absolute references to images and other files. In this case, you'll need to update the entire ...
user avatar
5 votes
Accepted

Is there a simple way to just insert a link to an image (without inserting an image)?

I found a solution based on the code of this page: https://core.trac.wordpress.org/ticket/22180 All attachment files have a post status of 'inherit'. So first you need to add "inherit" as one of the ...
user avatar
  • 3,133
5 votes
Accepted

How to create a link to jump to "Leave a comment" part?

The code below should be something similar to what you're looking for Inside the loop template you use for listing blogs (like index.php) you need something like this <a href="<?php ...
user avatar
  • 1,294
5 votes
Accepted

How to generate expiring URL?

Ok I came up with this add_action( 'wp_loaded', 'my_create_questionnaire_link'); function my_create_questionnaire_link(){ // this check is for demo, if you go to http://yoursite.demo/?create-my-...
user avatar
  • 2,229
5 votes
Accepted

Count and show Clicks on external links in a single page/post

Yes, it is possible. You can do this with ajax call that updates post meta field before the link is followed. In the example, I used admin and non-admin users who click the link and automatic ...
user avatar
4 votes
Accepted

How to show Disqus comments and pingbacks?

The plugin you mentioned is only a single function so it shouldn't be too heavy on your setup. It uses the comments_template filter to inject the pingbacks/trackbacks list into your page. But the ...
user avatar
  • 64.1k
4 votes
Accepted

Add a Menu Link (to a Wordpress Page) in the Admin Menu/Sidebar

To dynamically add menu items you can use WP_Query, specifically get_posts or get_pages. Get pages is more consistent. Here's an example to add all pages to the Pages admin menu. You can change ...
user avatar
  • 4,169
4 votes

Get_post_meta() won't return value

get_post_meta() only returns the output, but does not print it. You have to use either echo or the_meta() to print the actual output. href="<?php echo get_post_meta(get_the_id(), 'ramco-videos-...
user avatar
4 votes

Why is there a link tag with rel "profile" pointing to gmpg.org?

This profile enables your site to use the FOAF semantic insertions for richer metadata on your site. FOAF goes for Friend Of A Friend and aims to interconnect in "knowledge nodes" all the personal ...
user avatar
4 votes

External Links Not Working

This question is really too localized to get a solid answer and will most likely get closed. Here's a quick guide to narrow down what the issue is - but the fact that I can click the links just fine ...
user avatar
  • 19.6k

Only top scored, non community-wiki answers of a minimum length are eligible