Custom Code to get redirected to elementor editing mode

So, I have a multisite which allow the user to create their own blog (much like medium.com). Now I want when a logged in user clicks a link on front-end to edit a respective page he gets redirected to Elementor page builder editing mode, i.e. I didn't want him to go to the dashboard then Pages and then edit with Elementor rather direct to Elementor editor.
This is the link which redirects me to Elementor for my site
https://www.vedspace.com/wp-admin/post.php?post=5&action=elementor
But I can't use the same for my Subsites, so what I need is a way by which User gets redirected to Elementor editor for there site's page only.

  • Ash

    Hello RD

    Please try the following code:

    function create_elem_menu() {
    	global $wp_admin_bar;
    	global $post;
    
    	if( ! isset( $post->ID ) ) return;
    
    	$wp_admin_bar->add_menu( array( 'id' => $menu_id, 'title' => __( 'Edit page with Elemantor' ), 'href' => 'https://www.vedspace.com/wp-admin/post.php?post=' . $post->ID . '&action=elementor' ) );
    }
    
    add_action( 'admin_bar_menu', 'create_elem_menu', 2000 );

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    It should show a link in the admin bar called Edit with Elementor which should redirect to the builder page.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

  • Ash

    Hello RD

    Now I understand what you mean about the error :slight_smile:

    2. Bro, actually I want that button in a page on my main site, not on the admin bar I want something like a page where we have a separate button like a button for a page with ID one, then a for 2 that's all 2 page(buttons) is enough

    I am not sure about this, sorry. Do you want a page in main site which will contain edit link for all pages? Then from which subsite you want to show the page edit link?

    Or do you mean you have only 2 pages on each subsite and you want to list them all? Would you please explain a bit more?

    Cheers,
    Ash

  • RD

    hey Ash,

    I am not sure about this, sorry. Do you want a page in the main site which will contain edit link for all pages? Then from which subsite you want to show the page edit link?

    Yup, I want a page on the main site (let's say Page name= Dashboard)which contains link for 2 pages A homepage and Post page.
    See this is the whole scenario:
    When a user creates a subsite automatically two pages (Homepage ID=1 and Post page=2) will we created (I will use new blog template plugin to do that) now I didn't want my user to go dashboard>>pages>>edit with elementor instead I want a page on main site (which we named dashboard) which contain 2 buttons and by clicking 1 buttons user get redirected to Elementor editor for the Homepage(ID=1) and by clicking button 2 he gets redirected to Elementor editor for post page (ID=2) that's all. In simpler words a front-end way to edit pages using Elementor.
    Note: The homepage and post page I am talking about is the page of the subsite the user created not of the main site or of any other site.
    Hopes it will clear now

  • Ash

    Thanks, it's much better now :slight_smile: Please try the following code:

    add_shortcode( 'elem_subsite_page_edit', function() {
    	if( ! is_user_logged_in() )  return;
    	$user = get_userdata( get_current_user_id() );
    	$blog_id = $user->primary_blog;
    
    	ob_start();
    	?>
    	<div class="elem_edit_btn">
    		<a href="<?php echo get_site_url( $blog_id ) ?>/wp-admin/post.php?post=1&action=elementor">Edit home page</a>
    		<a href="<?php echo get_site_url( $blog_id ) ?>/wp-admin/post.php?post=2&action=elementor">Edit post page</a>
    	</div>
    	<?php
    	return ob_get_clean();
    } );

    Now use the following as shortcode:

    [elem_subsite_page_edit]

    Let me know if it works. Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.