• Good day dear WordPress community,

    I hope that this is the right category, since I mostly read about existing plugins having troubles working. However, I am creating my own plugin with above basic php knowledge.

    I am attempting to get the pagename, so that I can edit the page’s content when the url says /producten/ (Dutch for products)

    However, I have 2 problems

    The first being: the code I looked up on the internet, stated as resolved, doesn’t work. Here’s my piece of code to check if the code actually works:

    global $post;
    $pagename = get_post( $post )->post_name;
    ?>
    <script type="text/javascript">
    	<?php echo 'alert("Paginanaam: ' . $pagename . '")';?>
    </script>

    Here’s what will pop up: imgur

    This also brings me to the second problem: I want the content to change as soon as the pagename reaches state if ($pagename == "producten") However, I do not know which hook to execute my function for the page to change content:

    if ($pagename == "producten")
    {
    	add_action("wp_header","verander_titel");
    	function verander_titel()
    	{
    		?>
    		<div class="wrap">
    			<h3>It worked!</h3>
    		</div>
    		<?php
    	}
    	verander_titel();
    }

Viewing 1 replies (of 1 total)
  • Thread Starter patrickkasie

    (@patrickkasie)

    To the first problem, I found a solution with my boss (who has no knowledge in programming at all):
    Use the Shortcode API.
    That way he can add the function that I mentioned in problem 2 in every single page he wants, without having to overcome a lot of problems.

    However, now problem 2 is very crucial. I still do not seem to have a solution for that.

Viewing 1 replies (of 1 total)
  • The topic ‘[custom plugin]Can't get pagename’ is closed to new replies.